[R-pkg-devel] Forward function call

Neal Fultz n|u|tz @end|ng |rom gm@||@com
Mon Jun 8 21:25:21 CEST 2020


You will first need to convert the function call to an expression, then you
can modify the expression as appropriate.

Here's a somewhat contrived minimal example:

> f <- function(z, ...) match.call()
> aaa = f(a=1,2,3)
> str(aaa)
 language f(z = 2, a = 1, 3)
> aaa <- as.expression(aaa)
> str(aaa)
  expression(f(z = 2, a = 1, 3))
> aaa[[1]][[1]] <- expression(base::c)[[1]]
> str(aaa)
  expression(base::c(z = 2, a = 1, 3))
> eval(aaa)
z a
2 1 3



On Mon, Jun 8, 2020 at 12:12 PM Göran Broström <goran.brostrom using umu.se>
wrote:

> Hello,
>
> the function 'coxreg' in my package 'eha' is often just a wrapper for
> 'coxph' in survival, so I have code like
>
>      if (cox.ph){
>          Call <- match.call()
>          Call[[1]] <- as.name("coxph")
>          fit <- eval.parent(Call)
>          return(fit)
>      }
>
> which works since eha depends on survival. Now I am thinking of changing
> Depends to Imports, and I would like to change the code to
>
>      if (cox.ph){
>          Call <- match.call()
>          Call[[1]] <- as.name("survival::coxph")
>          fit <- eval.parent(Call)
>          return(fit)
>      }
>
> but this doesn't work, because the function name is turned into
> `survival::coxph` (with the backticks) and the evaluation fails.
>
> How can I solve this?
>
> Thanks, G,
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list