Can you use the fix through do.call?

I have code where it is more convenient to call fixthrough 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 him a name:

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

This time he fails with

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

It editdoesn’t work for recording either.

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

Can someone think of a reasonable workaround, please?

EDIT: after reflection, I forgot that it fixalways discards its response to the global environment, which is great for test cases, but not so good for use with functions. Joshua's excellent workaround does not apply to edit.

For bonus points, what do you call editthrough do.call?

+3
2

substitute, , .

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

, call:

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

, substitute, , . eval , , , , , .

, :

> as.name("dfr")==substitute(dfr)
[1] TRUE
+7

. :

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

- , dfr="dfr", what (). , :

do.call(fix,list(x="dfr"))
+3

Source: https://habr.com/ru/post/1768271/


All Articles