A Facebook friend asked:
R question: I have a file that contains a list of entries of the format "c(2.34306542445513, 1.07370083005978e-06)". How can I coax R to read such entries literally? In other words, I want to make an object from the entries. pars <- c(2.34306542445513, 1.07370083005978e-06)
My first response was to do this the hard way. Let's say we have a text file with one or multiple rows as described:
Before realizing that there is a much easier way, I pointed out that we can do what's been proposed using readLines, strsplit, paste, and as.numeric. I include this primarily to emphasize how easy it :
Anyway, shortly after posting this I realized that this could be done much more easily using the functions eval and parse:
P.S. please let me know if you prefer this new "text box" format for R code and session results, or my previous method of font only based demarcation (e.g., shown here, and in almost any other post on this blog).