Reputation: 432
I would like to include the config file in the head of my script through text connections.
However, it seems configr
could not deal with the text connection value as follows.
library(configr)
## set text connection
t1 <- textConnection("
[sim]
step=1000
[file]
namemap=d01,d02
dirmap=A,H,B,I
",
"r")
## Get config from text connection
b <- read.config(file=zz)
Thus, how could I pass the content of text connection to the read.config
?
Thanks for your help.
Upvotes: 0
Views: 41
Reputation: 206411
For whatever reason these package authors decided not to support connections and exclusivelt use file paths. The easiest workaround I guess is to write a temp file that gets removed when the function exits. For example
read_config_from_character <- function(val) {
tmpfile <- tempfile()
write(val, tmpfile)
on.exit(file.remove(tmpfile))
read.config(tmpfile)
}
Then you could call it like
configstr <- "
[sim]
step=1000
[file]
namemap=d01,d02
dirmap=A,H,B,I
"
read_config_from_character(configstr)
Upvotes: 1