xxxxxxxxxxparse_string <- function(string) { p <- getParseData(parse(text = string)) p[p$text != "", c("text", "token")]}parse_string("x <- mtcars[mtcars$cyl == 4, ]")A test of WebR chunks in Quarto
The simple function below helps expose R’s fundamental ‘tokens’. I wrote recently about parsing R in this way.
Click ‘Run code’ to declare the function and execute the example.
xxxxxxxxxxparse_string <- function(string) { p <- getParseData(parse(text = string)) p[p$text != "", c("text", "token")]}parse_string("x <- mtcars[mtcars$cyl == 4, ]")Now it’s your turn. Change the value of r_string below to a valid line of R code and then click ‘Run code’.
xxxxxxxxxxr_string <- "x <- 1" # change the stringparse_string(r_string)You can keep changing the value of r_string and pressing ‘Run code’ to see the effect.
This is a test of:
You can find the source code for this page on GitHub.