Jorgen Harmse
2023-Sep-20 14:13 UTC
[R] Could you manually replicate execution of a R function
There may be collisions between variables in .GlobalEnv and variables in the
function-call environment, and the parent of the function-call environment
probably includes functions & other variables not available in .GlobalEnv.
(If the function calls substitute or anything like that then the problem becomes
even harder.) I would probably use the debugger to step into the function. If
you want more control then create an environment that resembles what would be
created in a function call:
env.func <- new.env(parent=environment(f))
delayedAssign(assign.env=env.func, ?.) for everything you pass in
delayedAssign(assign.env=env.func, eval.env=env.func, ?.) for anything that will
take a default value
eval(envir=env.func, ?.) or evalq(envir=env.func, ?.) to execute parts of the
function body or anything else
You can even coerce body(f) to a character, strip the leading ?{?, and
parse(text=?.) to break the function into expressions. That might be easier than
copy-pasting function code.
Regards,
Jorgen Harmse.
Message: 1
Date: Tue, 19 Sep 2023 23:09:18 +0530
From: Brian Smith <briansmith199312 at gmail.com>
To: r-help at r-project.org
Subject: [R] Could you manually replicate execution of a R function
Message-ID:
<CAHUBDY_wr_uWTK3t2bU+EmVGvKRNHw4DdvmqMq+F0rq6R3OxGw at
mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
I have trying to replicate a function from rugarch package manually.
Below is the calculation based on the function,
?
[[alternative HTML version deleted]]