{
##### Example 1 -------------------------------------------------------------
# Simple assignation will assign 'b' in parceval environment (which is
# associated to a function and different from .GlobalEnv, by definition).
# Double assignation will put 'b' in .GlobalEnv.
# (similar to assign(x = "b",value = 1,envir = .GlobalEnv))
a <- 1
parceval("print(a)")
##### Example 2 -------------------------------------------------------------
# use rowwise to directly use parceval in a tibble, or use a for loop.
library(dplyr)
library(tidyr)
tibble(cars) %>%
mutate(
to_eval = paste0(speed,"/",dist)) %>%
rowwise() %>%
mutate(
eval = parceval(to_eval))
##### Example 3 -------------------------------------------------------------
# parceval can be parcevaled itself!
code_R <-
'as_tibble(cars) %>%
mutate(
to_eval = paste0(speed,"/",dist)) %>%
rowwise() %>%
mutate(
eval = parceval(to_eval))'
cat(code_R)
parceval(code_R)
}
Run the code above in your browser using DataLab