[Rd] eval a SYMSXP from C

From: Whit Armstrong <armstrong.whit_at_gmail.com>
Date: Mon, 16 Apr 2012 17:53:02 -0400


Can someone offer some advice on how to properly evaluate a SYMSXP from a .Call ?

I have the following in R:

variable xn, with an attribute "mu" which references the variable mu in the global environment.

I know "references" is a loose term; mu was defined in this fashion as a way to implement deferred binding:

foo <- function(x,mu) {

    attr(x,"mu") <- substitute(mu)
    x
}

mu <- 2.0
xn <- foo(rnorm(100),mu)

> typeof(attr(xn,"mu"))

[1] "symbol"
> eval(attr(xn,"mu"))

[1] 2
>

In a .Call, I am attempting to eval the SYMSXP as follows:

SEXP mu_ = Rf_getAttrib(x_,Rf_install("mu"));

if(TYPEOF(mu_)==SYMSXP) {
  mu_ = Rf_eval(Rf_lang1(mu_),R_GlobalEnv);
}

However, when running this code, I get the following error: Error in logp(xn) : could not find function "mu"

Do I need to create an expression of c("get", "mu") to force the name lookup to evaluate the SYMSXP?

Thanks,
Whit



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 16 Apr 2012 - 21:55:14 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Apr 2012 - 01:00:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive