Primo Petri
Primo Petri

Reputation: 434

Source a vector of characters

The following script works perfectly well. Still, I would like to know if it possible to source directly the vector x.

x <- c("print (\"Hallo world\")", "print (\"(Just an example)\")")
temporary_file <- tempfile()
write(x, file = temporary_file )
source(temporary_file)

Upvotes: 0

Views: 95

Answers (1)

bgoldst
bgoldst

Reputation: 35314

x <- c("print (\"Hallo world\")", "print (\"(Just an example)\")");
eval(parse(text=x));
## [1] "Hallo world"
## [1] "(Just an example)"

Upvotes: 3

Related Questions