Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

valid_syntax

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)

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.