[R] quotes within quotes
janet rosenbaum
jerosenb at hcs.harvard.edu
Wed Apr 9 18:19:58 CEST 2003
Thanks for all the suggestions.
Some people asked why I'm bothering with all this. This is just
the toy code I'm trying on the command-line, but the two errors below
are the same as I get in the real code.
It's true that I could avoid the modularity, but it improves readability
and maintainability immensely.
Here are my results to three suggestions. The pathnames below are all
abbreviated for readability.
1. do.call seems to work.
Both of the following successfully read the data in:
> read.dta("C:/Documents and Settings/mexchn_gary.dta", convert.factors=FALSE)
> do.call("read.dta", list(file="C:/Documents and Settings/mexchn_gary.dta", convert.factors=FALSE))
2. quotes within quotes:
Correspondants suggested using single quotes or backslashes to escape
the quotes. It turns out R interprets both the same way.
> cmd <- "read.dta"
> opt <- "convert.factors=FALSE"
> data.file <- 'file="C:/Documents and Settings/mexchn_gary.dta"'
> do.call(cmd, list(data.file, opt))
Error in read.dta("file=\"C:/Documents and Settings/mexchn_gary.dta\"", :
unable to open file
3. Avoid using quotes within quotes
When we call read.dta and don't use "file=", it works (see #1), but not
inside do.call.
> data.file <- "C:/Documents and Settings/mexchn_gary.dta"
> do.call(cmd, list(data.file, opt))
Error in if (convert.dates) { : argument is not interpretable as
logical
Thanks,
Janet
More information about the R-help
mailing list