[R] Could you manually replicate execution of a R function

Jorgen Harmse JH@rm@e @end|ng |rom roku@com
Wed Sep 20 16:13:02 CEST 2023

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.

Jorgen Harmse.

Message: 1
Date: Tue, 19 Sep 2023 23:09:18 +0530
From: Brian Smith <briansmith199312 using gmail.com>
To: r-help using r-project.org
Subject: [R] Could you manually replicate execution of a R function
        <CAHUBDY_wr_uWTK3t2bU+EmVGvKRNHw4DdvmqMq+F0rq6R3OxGw using mail.gmail.com>
Content-Type: text/plain; charset="utf-8"


I have trying to replicate a function from rugarch package manually.
Below is the calculation based on the function,


	[[alternative HTML version deleted]]

More information about the R-help mailing list