valid_syntax: Check whether a string is valid R code

View source: R/valid_syntax.R View source: R/utils.R

valid_syntaxR 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

ucbds-infra/ottr documentation built on Feb. 24, 2024, 2:31 a.m.