Take the 2-minute tour ×

I have some code where it is more convenient to call fix via do.call, rather than directly. Any old data frame will work for this example:

dfr <- data.frame(x = 1:5, y = letters[1:5])

The obvious first attempt is

do.call("fix", list(dfr))

Unfortunately, this fails with

Error in fix(list(x = 1:5, y = 1:5)) : 'fix' requires a name

So, we give it a name:

do.call("fix", list(dfr = dfr))

This time it fails with

Error in is.name(subx) : 'subx' is missing

For the record, edit doesn't work either.

dfr <- do.call("edit", list(dfr = dfr))

Can anyone think of a sensible workaround, please?

EDIT: Upon reflection, I'd forgotten that fix always dumps its answer into the global environment, which is fine for test examples, but not so good for use with functions. Joshua's excellent workaround doesn't extend to use with edit.

For bonus points, how do you call edit via do.call?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can use substitute, which is also useful for when you want to use variable names as labels.


Edit for clarity

It is easier to see how this works by using the call command:

> call("fix",dfr)
fix(list(x = c(1, 2, 3, 4, 5), y = 1:5))
> call("fix",substitute(dfr))

Thus when you use substitute the command that is being created uses the name of the symbol rather than the evaluated symbol. If you wrap an eval around these expressions you see that the first example gives the same error you encountered, and the second example works as expected.

After reading hadley's link it becomes clearer what is being evaluated:

> as.name("dfr")==substitute(dfr)
[1] TRUE
share|improve this answer
This also works for edit. Hurrah! –  Richie Cotton Oct 6 '10 at 16:28
I find that any occasion I use substitute has typically been preceded by an extended session of programming-induced tourettes. If anyone knows of a simple explanation of how and when to use it, I'd be grateful. –  Richie Cotton Oct 6 '10 at 16:31
@Richie: try github.com/hadley/devtools/wiki/Evaluation –  hadley Oct 6 '10 at 19:10
@hadley: Thanks for the link; it's much clearer than the R language manual. –  Richie Cotton Oct 7 '10 at 11:07
You're better off testing for equality with identical() –  hadley Oct 7 '10 at 13:22

The first error gives you a hint. This works:


You would still get the same error on your second try even if you used dfr="dfr" because the named list needs names of the arguments to what (the function). So your second try should be:

share|improve this answer
@Johua: Doh! I feel mildly silly. Cheers. –  Richie Cotton Oct 6 '10 at 16:04
@Richie: try James' answer too, since it's more R-like. –  Joshua Ulrich Oct 6 '10 at 16:11
@Joshua: Marking James as the official answer, on account of how it solves the edit problem too, but remind me I owe you an extra upvote for that excellent speedy response. –  Richie Cotton Oct 6 '10 at 16:34
@Richie: no worries; it's the better answer. –  Joshua Ulrich Oct 6 '10 at 16:36
No, this is the better answer because it correctly interprets the input to fix. –  hadley Oct 6 '10 at 19:12

Your Answer


