R: Check if the syntax of the code is valid

valid_syntax {xfun} | R Documentation

## Check if the syntax of the code is valid

### Description

Try to `parse()` the code and see if an error occurs.

### Usage

    valid_syntax(code, silent = TRUE)

### Arguments

`code` | A character vector of R source code.
`silent` | Whether to suppress the error message when the code is not valid.

### Value

`TRUE` if the code could be parsed, otherwise `FALSE`.

### Examples

    xfun::valid_syntax("1+1")
    xfun::valid_syntax("1+")
    xfun::valid_syntax(c("if(T){1+1}", "else {2+2}"), silent = FALSE)

[Package xfun version 0.29 Index]