I think I will go with the suggestion of creating a new empty environment,
adding only the argument parsing function. Moreover I will use the same
name as the user-facing function that's being invoked, i.e.,
foo <- function(...) {
call <- match.call(expand.dots = TRUE)
call[[1]] <- quote(pa
If you want the name of the function to appear, then you can put the
function in an environment whose parent is where most of the evaluation
should take place. For example,
f <- function(...) {
call <- match.call(expand.dots = TRUE)
call[[1]] <- quote(parse_args)
envir <- new.env(parent
Here's another suggestion, not sure if it's any good, but you could
structure your functions like
parse_args <- function (envir = parent.frame())
{
evalq(list(a = a, b = b, ..., y = y, z = z), envir)
<...>
}
exported_fun <- function (a, b, ..., y, z)
{
parse_args()
<...>
}
It's s
You could add an 'envir' argument to parse_args() and do your eval(...,
envir=envir) stuff inside parse_args(). Then change
call[[1]] <- quote(pense:::parse_args)
args <- eval.parent(call)
to
call[[1]] <- quote(parse_args)
call$envir <- parent.frame()
args <- eval(call)
[That code is
Thank you both for the suggestions. I would prefer a clean stack trace in
case of errors as input errors are caught by this function and hence users
might very well see errors emitted from it. It seems more informative to me
if the error message would say "Error in .parse_argsā¦" than "Error in
new.
David,
why not
call[[1]] <- parse_args
The assignment is evaluated in your namespace so that makes sure the call is
that of your function. The only downside I see is that in a stack trace you'll
see the definition instead of the name.
Or possibly
do.call(parse_args, as.list(call[-1]))
Cheers
Dear List,
I am working on updating the pense package and refactored some of the
methods. I have several functions which take the same arguments, hence I'm
sending all these arguments to an internal function, called `parse_args()`.
Since I want to evaluate the arguments in the caller's environment