Learn R Programming

TheOpenAIR (version 0.1.0)

is_r: Check if a character string contains valid R code

Description

This function takes a character string as input and attempts to parse it as R code using the `parse` function. If the parsing is successful, the function returns TRUE, indicating that the input string contains valid R code. If parsing fails, the function returns FALSE.

Usage

is_r(code)

Value

A logical value indicating whether the input code string contains valid R code or not.

Arguments

code

A character string containing the R code to be checked.

Examples

Run this code
# Valid R code
valid_code <- "x <- 5; y <- 10; z <- x + y"
is_r(valid_code)

# Invalid R code
invalid_code <- "x <- 5 + 'a'"
is_r(invalid_code)

Run the code above in your browser using DataLab