After making changes to a R script, is there a way to check its syntax by running a command, before running the R script itself?
CodePudding user response:
There is lint() from the lint package:
lintr::lint("tets.r")
#> tets.r:1:6: style: Place a space before left parenthesis, except in a function call.
#> is.na(((NA))
#> ^
#> tets.r:1:12: error: unexpected end of input
#> is.na(((NA))
#> ^
The tested file contains only this wrong code
is.na(((NA))
You can customise what lint() checks. By default, it is quite noisy about code style (which is the main reason I use it).
CodePudding user response:
Base R has parse which will parse a script without running it.
parse("myscript.R")
The codetools, package which comes with R, has checkUsage and checkUsagePackage to check single functions and packages respectively.
