Closed JoniColeman closed 11 months ago
Regex changed – code checked against data. Review re-requested.
library(lintr)
mhq_lints <- linters_with_defaults(
object_name_linter(styles = c("symbol", "CamelCase", "snake_case", "lowercase"))
)
lint("scripts/SelfReported.Rmd", linters = mhq_lints, exclude = "##")
MHQ2/scripts/SelfReported.Rmd:19:13: style: [quotes_linter] Only use double-quotes.
comment = '',
^~
MHQ2/scripts/SelfReported.Rmd:22:2: style: [indentation_linter] Indentation should be 0 spaces but is 2 spaces.
)
~^
MHQ2/scripts/SelfReported.Rmd:39:38: style: [brace_linter] There should be a space before an opening curly brace.
package_install <- function(packages){
^
MHQ2/scripts/SelfReported.Rmd:39:38: style: [paren_body_linter] There should be a space between a right parenthesis and a body expression.
package_install <- function(packages){
^
MHQ2/scripts/SelfReported.Rmd:41:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces.
for(x in packages){
~^
MHQ2/scripts/SelfReported.Rmd:41:8: style: [spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.
for(x in packages){
^
MHQ2/scripts/SelfReported.Rmd:42:1: style: [trailing_whitespace_linter] Trailing whitespace is superfluous.
^~~~
MHQ2/scripts/SelfReported.Rmd:43:8: style: [indentation_linter] Indentation should be 4 spaces but is 8 spaces.
install.packages(x, dependencies = TRUE)
~~~^
MHQ2/scripts/SelfReported.Rmd:44:1: style: [trailing_whitespace_linter] Trailing whitespace is superfluous.
^
MHQ2/scripts/SelfReported.Rmd:44:1: style: [whitespace_linter] Use spaces to indent, not tabs.
^
MHQ2/scripts/SelfReported.Rmd:45:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces.
}
~^
MHQ2/scripts/SelfReported.Rmd:45:6: style: [trailing_whitespace_linter] Trailing whitespace is superfluous.
}
^~~~~
MHQ2/scripts/SelfReported.Rmd:52:3: style: [commented_code_linter] Commented code should be removed.
# packages <- c("data.table","tidyverse","dplyr")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:53:3: style: [commented_code_linter] Commented code should be removed.
# package_install(packages)
^~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:61:28: style: [commas_linter] Commas should always have a space after.
packages <- c("data.table","tidyverse","dplyr")
^
MHQ2/scripts/SelfReported.Rmd:61:40: style: [commas_linter] Commas should always have a space after.
packages <- c("data.table","tidyverse","dplyr")
^
MHQ2/scripts/SelfReported.Rmd:70:5: style: [infix_spaces_linter] Put spaces around all infix operators.
MHQ2<-fread(args[1], data.table=F)
^~
MHQ2/scripts/SelfReported.Rmd:70:32: style: [infix_spaces_linter] Put spaces around all infix operators.
MHQ2<-fread(args[1], data.table=F)
^
MHQ2/scripts/SelfReported.Rmd:70:34: style: [T_and_F_symbol_linter] Use FALSE instead of the symbol F.
MHQ2<-fread(args[1], data.table=F)
~^
MHQ2/scripts/SelfReported.Rmd:101:44: style: [infix_spaces_linter] Put spaces around all infix operators.
MHQ2$SelfReportedDiagnosisMHQ2016Compatible<- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(1:15,17:19) %in% row) > 0, 1, 0))
^~
MHQ2/scripts/SelfReported.Rmd:101:59: style: [commas_linter] Commas should always have a space after.
MHQ2$SelfReportedDiagnosisMHQ2016Compatible<- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(1:15,17:19) %in% row) > 0, 1, 0))
^
MHQ2/scripts/SelfReported.Rmd:101:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 155 characters.
MHQ2$SelfReportedDiagnosisMHQ2016Compatible<- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(1:15,17:19) %in% row) > 0, 1, 0))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:101:128: style: [commas_linter] Commas should always have a space after.
MHQ2$SelfReportedDiagnosisMHQ2016Compatible<- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(1:15,17:19) %in% row) > 0, 1, 0))
^
MHQ2/scripts/SelfReported.Rmd:112:49: style: [commas_linter] Commas should always have a space after.
MHQ2$SelfReportedAnxietyDisorder <- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(10:13,15) %in% row) > 0, 1, 0))
^
MHQ2/scripts/SelfReported.Rmd:112:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 143 characters.
MHQ2$SelfReportedAnxietyDisorder <- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(10:13,15) %in% row) > 0, 1, 0))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:112:119: style: [commas_linter] Commas should always have a space after.
MHQ2$SelfReportedAnxietyDisorder <- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(10:13,15) %in% row) > 0, 1, 0))
^
MHQ2/scripts/SelfReported.Rmd:122:48: style: [commas_linter] Commas should always have a space after.
MHQ2$SelfReportedEatingDisorder <- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(17:20) %in% row) > 0, 1, 0))
^
MHQ2/scripts/SelfReported.Rmd:122:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 139 characters.
MHQ2$SelfReportedEatingDisorder <- apply(MHQ2[,grep("^29000-", colnames(MHQ2))], 1, function(row) ifelse(sum(c(17:20) %in% row) > 0, 1, 0))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:130:14: error: [error] unexpected symbol
~~TODO: This needs to be done as part of the overarching script as it relies on otuput from multiple modules~~
^
MHQ2/scripts/SelfReported.Rmd:130:81: style: [line_length_linter] Lines should not be more than 80 characters. This line is 111 characters.
~~TODO: This needs to be done as part of the overarching script as it relies on otuput from multiple modules~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MHQ2/scripts/SelfReported.Rmd:130:111: style: [trailing_whitespace_linter] Trailing whitespace is superfluous.
~~TODO: This needs to be done as part of the overarching script as it relies on otuput from multiple modules~~
^
MHQ2/scripts/SelfReported.Rmd:131:1: style: [trailing_blank_lines_linter] Trailing blank lines are superfluous.
Need to lintR new code and resolve issues
Confirmed code is more efficient and gives correct output. Merging and closing.
Markdown sections need to written such that comments are properly tabulated. This is best done by making them into lists as described here: https://www.markdownguide.org/cheat-sheet/
https://github.com/ColemanResearchGroup/MHQ2/blob/850999b68f0d5a2ba61479cab2fa2301436a0dea/scripts/SelfReported.Rmd#L85
The regular expression should be changed to a more specific pattern like
"^29000-"
so that it matches field 29000 exactly, and not potential future fields like 129000 or 290000.