Skip to content

quotes within quotes

2 messages · Janet Rosenbaum, Brian Ripley

#
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:
2.  quotes within quotes:

Correspondants suggested using single quotes or backslashes to escape 
the quotes.  It turns out R interprets both the same way.
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.
Error in if (convert.dates) { : argument is not interpretable as
 logical


Thanks,

Janet
#
On Wed, 9 Apr 2003, janet rosenbaum wrote:

            
I think those people were right: you seem to be misunderstanding do.call.
That's nothing to do with quotes within quotes. You should be giving a 
*named list* to do.call, not a list of "var=value" strings.
It's your `opt' which is in the wrong format:
	
cmd <- "read.dta"
cf <- FALSE
data.file <- "C:/Documents and Settings/mexchn_gary.dta"
do.call(cmd, list(file=data.file, convert.factors=cf))

is a correct way to use do.call. You could also do something like

args <- list(data.file, cf)
names(args) <- c("file", "convert.factors")
do.call(cmd, args)

and that's the sort of thing discussed for useful examples in section 3.5 
of `S Programming'.