valid_syntax {ottr} | R Documentation |
Check whether a string is valid R code
Description
Determine whether a code snippet has any syntax errors.
Determine whether a code snippet has any syntax errors.
Usage
valid_syntax(script)
valid_syntax(script)
Arguments
script |
The code snippet |
Value
Whether the code snippet is valid (can be parsed with parse
)
Whether the code snippet is valid (can be parsed with parse
)
Examples
s = "
a = TRUE
b = c(1, 2, 3)
d = function(x) x ^ 2
f = d(b)
"
valid_syntax(s)
#> [1] TRUE
s = "
if (TRUE) {
a = c(1, 2)
"
valid_syntax(s)
#> [1] FALSE
s = "
a = TRUE
b = c(1, 2, 3)
d = function(x) x ^ 2
f = d(b)
"
valid_syntax(s)
#> [1] TRUE
s = "
if (TRUE) {
a = c(1, 2)
"
valid_syntax(s)
#> [1] FALSE
[Package ottr version 1.5.0 Index]