Question



How to execute R code inside a string variable?

How to execute R code inside a string variable?

i.e. suppose I had the following R code:
```{r}
doThisMath<-"3+4"
```
how do I call string variable doThisMath to return 7?






Answers and follow-up questions





Answer or follow-up question 1

Dear student,

eval(parse(text=doThisMath))
[1] 7

fyi: first search result in Google when you search for "How to execute R code inside a string variable?"
https://stat.ethz.ch/pipermail/r-help/2011-August/285614.html

Michel Ballings


Answer or follow-up question 2

How would we make sure that the percentage of 1s (and also 0s) in a starting data frame be identical to a training and test set?





Sign in to be able to add an answer or mark this question as resolved.