Displaying 20 results from an estimated 211 matches for "r_globalenv".
2009 Sep 29
3
How do I access class slots from C?
...str,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal;
int errorOccurred,nx,ny,i,j;
double *v;
const char *x,*y;
Rf_initEmbeddedR(argc, argv);
// loading fPortfolio
PROTECT(e = lang2(install("library"), mkString("fPortfolio")));
R_tryEval(e, R_GlobalEnv, NULL);
UNPROTECT(1);
// creating a default portfolioSpec object
PROTECT(e=lang1(install("portfolioSpec")));
PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL));
// creating a portfolioData object
PROTECT(e=lang4(install("c"),mkString("SBI"),mkStr...
2009 Sep 16
2
I want to get a reference to this time series object
...{
SEXP e,c,portSpec,portData,portConstr,portVal,tsAssets;
int errorOccurred,nx,ny,i,j;
double *v;
const char *x,*y;
Rf_initEmbeddedR(argc, argv);
// loading fPortfolio
PROTECT(e = lang2(install("library"), mkString("fPortfolio")));
R_tryEval(e, R_GlobalEnv, NULL);
UNPROTECT(1);
// creating a default portfolioSpec object
PROTECT(e=lang1(install("portfolioSpec")));
PROTECT(portSpec=R_tryEval(e,R_GlobalEnv, NULL));
// creating a portfolioData object
PROTECT(e=lang4(install("c"),mkString("SBI"),mkStr...
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
...g3=function(t) showstack()
g2=function(w) g3(w)
g1=function(z) g2(z)
g=function(y) g1(y)
g()
# outputs:
# <environment: 0xb5ef810>
# <environment: 0xb5ef6f8>
# <environment: 0xb5ef5e0>
# <environment: 0xb5ef4c8>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# ...
cat(capture.output(g()),sep="\n")
# outputs:
# <environment: 0x8106a30>
# <environment: 0x810...
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
...g3=function(t) showstack()
g2=function(w) g3(w)
g1=function(z) g2(z)
g=function(y) g1(y)
g()
# outputs:
# <environment: 0xb5ef810>
# <environment: 0xb5ef6f8>
# <environment: 0xb5ef5e0>
# <environment: 0xb5ef4c8>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# ...
cat(capture.output(g()),sep="\n")
# outputs:
# <environment: 0x8106a30>
# <environment: 0x810...
2015 Oct 09
4
A where() functions that does what exists() does but return the environment when object lives?
...ing for a
similar function to exists() that returns the environment where the
object "foo" exists, iff at all. If not found, NULL is returned.
Does that exist?
EXAMPLE #1:
> sample2 <- base::sample
> env <- where("sample2", inherits=TRUE)
> env
<environment: R_GlobalEnv>
Note the difference to:
> obj <- get("sample2", inherits=TRUE)
> environment(obj)
<environment: namespace:base>
EXAMPLE #2:
> a <- 1
> foo <- function() { b <- 2; list(a=where("a", inherits=TRUE), b=where("b", inherits=TRUE)) }
&g...
2020 Mar 24
2
help with rchk warnings on Rf_eval(Rf_lang2(...))
> Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv));
The call should be protected before evaluation though. So more like:
Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x));
return Rcpp_fast_eval(call, R_GlobalEnv);
Best,
Lionel
On 3/23/20, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>
> On 23 March 2020 at 17:07, Ben Bol...
2003 May 28
0
R_GlobalEnv
Hi,
I'm trying to access the current R global environment from
within C, using R_GlobalEnv.
In the example below, Rgui (R 1.7.0. Win2K) crashes when I try
to run assignValueToFooInR_GlobalEnv, but not when I run
assignValueToFooInRhoEnv with Rho=.GlobalEnv. Can anyone tell me why?
[ My motivation is that I want use defineVar to initialise a
workingEnvironment (corresponding to Valu...
2014 May 17
1
environment question
...anual/R-devel/library/base/html/environment.html
"If |fun| is a function or a formula then |environment(fun)| returns the
environment associated with that function or formula. If |fun| is |NULL|
then the current evaluation environment is returned."
> environment()
<environment: R_GlobalEnv>
> environment(environment)
<environment: namespace:base>
This makes sense, however I have two questions on things that don't seem
to make sense:
1.
> .Internal(environment(NULL))
<environment: base>
Since we are calling from R_GlobalEnv, how can the calling environm...
2006 May 17
1
protect/unprotect howto in C code
...9;error in unprotect: stack imbalance' problem
and I am curious about two basic questions on the use of PROTECT and
UNPROTECT, which I could not figure out:
- which objects have to be protected, namely, if the code is something like:
SEXP fun, e;
/* get the expression e ... */
fun = eval(e, R_GlobalEnv);
/* or like this?: PROTECT(fun = eval(e, R_GlobalEnv)); */
PROTECT(fun = VECTOR_ELT(fun, 1));
/* do more things with fun ... */
does one need to protect the result of a call to 'eval' immediately? And how
about R_tryEval?
While searching for code examples in the sources, I found both pro...
2016 Dec 12
0
[RE: why does parent.frame() cycle when called from inside capture.output()?]
...g3=function(t) showstack()
g2=function(w) g3(w)
g1=function(z) g2(z)
g=function(y) g1(y)
g()
# outputs:
# <environment: 0xb5ef810>
# <environment: 0xb5ef6f8>
# <environment: 0xb5ef5e0>
# <environment: 0xb5ef4c8>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# <environment: R_GlobalEnv>
# ...
cat(capture.output(g()),sep="\n")
# outputs:
# <environment: 0x8106a30>
# <environment: 0x810...
2016 Dec 08
2
methods(`|`) lists all functions?
...t;normal" way? I used 'ls("package:base")' for the exercise,
because I saw this call used somewhere as an example, but I couldn't
find that "package:" syntax documented under ls()... Also found this
confusing:
> environmentName(globalenv())
[1] "R_GlobalEnv"
> ls("R_GlobalEnv")
Error in as.environment(pos) :
no item called "R_GlobalEnv" on the search list
So I'm not sure if "package:base" is naming an environment, or if
there are different ways to name environments and ls() is using one
form whi...
2015 Oct 13
1
A where() functions that does what exists() does but return the environment when object lives?
...; object "foo" exists, iff at all. If not found, NULL is returned.
>> Does that exist?
>>
>> EXAMPLE #1:
>>
>>> sample2 <- base::sample
>>> env <- where("sample2", inherits=TRUE)
>>> env
>>
>> <environment: R_GlobalEnv>
>>
>> Note the difference to:
>>
>>> obj <- get("sample2", inherits=TRUE)
>>> environment(obj)
>>
>> <environment: namespace:base>
>>
>>
>> EXAMPLE #2:
>>
>>> a <- 1
>>> foo <- fun...
2004 Oct 08
2
R-2.0.0 findVar and findFun question
...ric function in usemethod
Alternatively, using Rf_findFun(...) seems OK in this context, but crashes if you
call it with an unexisting function name. Rf_findVar does not crash in this case,
but returns an unbound value.
My workaround for now is as follows:
fun = Rf_findVar(Rf_install(ident), R_GlobalEnv);
if (fun != R_UnboundValue) {
fun = Rf_findFun(Rf_install(ident), R_GlobalEnv);
R_tryEval(fun, ...);
}
I did some checking on the R object pointers and indeed for generic functions
Rf_findFun and Rf_findVar return different pointers (and therefore different
function object...
2020 Jun 30
2
Build a R call at C level
...luating R expression
from C) and I tried to build a simple call to the sum function. Please see
below.
call_to_sum <- inline::cfunction(
language = "C",
sig = c(x = "SEXP"), body = "
SEXP e = PROTECT(lang2(install(\"sum\"), x));
SEXP ans = PROTECT(eval(e, R_GlobalEnv));
UNPROTECT(2);
return ans;
")
call_to_sum(1:3)
The above works. My question is how do I add the argument "na.rm=TRUE" at C
level to the above call? I have tried various things based on what is in
section 5.11 but I did not manage to get it to work.
Thank you
Best regards
[[al...
2009 Jan 08
1
Callbacks seems to get GCed.
...{"set_callback1", (DL_FUNC) &set_callback1, 1},
{"set_callback2", (DL_FUNC) &set_callback2, 1},
{NULL}
};
void r_trigger_callback1()
{
int errorOccurred;
SEXP f = NULL;
f = allocVector(LANGSXP, 1);
SETCAR(f, callback1);
PROTECT(f);
R_tryEval(f, R_GlobalEnv, &errorOccurred);
UNPROTECT(1);
}
void r_trigger_callback2()
{
int errorOccurred;
SEXP f = NULL;
f = allocVector(LANGSXP, 1);
SETCAR(f, callback2);
PROTECT(f);
R_tryEval(f, R_GlobalEnv, &errorOccurred);
UNPROTECT(1);
}
void r_exec(char *code)
{
SEXP cmdSexp, c...
2010 Sep 09
0
calling Rf_initEmbeddedR error
...nt Argc2 = 1;
char *Argv2[] = {"Rtest_2"};
// Init R(first)
Rf_initEmbeddedR(Argc1, Argv1);
// R package load
SEXP e = R_NilValue;
SEXP r = R_NilValue;
PROTECT(e = lang2(install("source"), mkString("hreg.r")));
r = R_tryEval(e, R_GlobalEnv, NULL); // -----> success
UNPROTECT(1);
// Function load
SEXP fun;
PROTECT(e = allocVector(LANGSXP, 3));
fun = findFun(install("hreg"), R_GlobalEnv);
if(fun == R_NilValue) // -----> success
{
UNPROTECT(1);...
2012 Sep 29
1
About the scope of a variable and the save() method
In the following test, the variable x is supposed to be modified within the
function test.save.x. It works as expected util using the save command.
# initialize x.file
x <- 1
save(x, file="x.file")
rm(x) # Remove x from R_GlobalEnv
exists("x") # FALSE
# define test
test.save.x <- function(){
save.x <- function(){
save(x, file="x.file")
}
change.x <- function(){
load("x.file", parent.frame(n = 2)) # load x to upper level frame
x <<- x + 1
save.x() # If comment this line. x variabl...
2014 Jun 25
1
Need help on calling Head from C
Hi ,
I am trying to call head function from C . My doubt is with the parameter
n,how to pass it .
PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));
PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
head = PROTECT(eval(head,R_GlobalEnv));
I tried the above following , it seemed to be not working . Can you please
help.
Thanks
[[alternative HTML version deleted]]
2020 Jun 30
3
Build a R call at C level
..."SEXP"), body = "
>
> SEXP e = PROTECT(lang2(install(\"sum\"), x));
> SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
> SETCDR(CDR(e), r_true);
> SET_TAG(CDDR(e), install(\"na.rm\"));
> Rf_PrintValue(e);
> SEXP ans = PROTECT(eval(e, R_GlobalEnv));
> UNPROTECT(3);
> return ans;
>
> ")
>
> call_to_sum(c(1L,NA,3L))
>
> On Tue, Jun 30, 2020 at 10:08 AM Morgan Morgan
> <morgan.emailbox at gmail.com> wrote:
>> Hi All,
>>
>> I was reading the R extension manual section 5.11 ( Evaluating R e...
2013 Aug 14
1
local variable assignment: first copies from higher frame?
...FALSE, ifnotfound = NA)[[1]]))
print(closure_environment)
cat(str(mget("my_list", envir = closure_environment, inherits =
FALSE, ifnotfound = NA)[[1]]))
}
> my_list <- list(x = 1, y = 2)
> tempf(0, local = TRUE)
<environment: 0xcb47cb8>
logi NA
<environment: R_GlobalEnv>
List of 2
$ x: num 1
$ y: num 2
<environment: 0xcb47cb8>
List of 2
$ x: num 0
$ y: num 2
<environment: R_GlobalEnv>
List of 2
$ x: num 1
$ y: num 2
> tempf(0, local = FALSE)
<environment: 0xbf4df50>
logi NA
<environment: R_GlobalEnv>
List of 2
$ x: num 1
$ y:...