search for: lang2

Displaying 20 results from an estimated 35 matches for "lang2".

Did you mean: lang
2003 Nov 03
2
lang2(...) with two and more arguments
Dear R-help, how could I create an R call in C code using lang2 with 2 and more arguments? I tried this code: SEXP f(SEXP fn, SEXP rho) { SEXP R_fcall, x, y; PROTECT(R_fcall = lang2(fn, R_NilValue)); PROTECT(x = allocVector(REALSXP, 1)); PROTECT(y = allocVector(REALSXP, 1)); REAL(x)[0] = 10; REAL(y)[0] = 20; SETCADR(R_fcall, x);...
2014 Apr 03
1
question regarding lang2 command in C
Hi , I am asking too many questions , sorry for that . I am creating a data frame in C itself , reading a table . The data frame calling code looks like this ====================================== *PROTECT(dfm=lang2(install("data.frame"),df));* *SEXP res = PROTECT(eval(dfm,R_GlobalEnv));* UNPROTECT(2); return res; ================================== It works fine , now the problem is I want to do the below one from C itself ( adding the *stringsAsFactors = FALSE* parameter) df <- data.frame(ge...
2012 Mar 27
2
PROTECT help
...nalized Cox models, the C code needs to get the value of the penalty and the penalty is an arbitrary S expression passed down from top level. Terry T ---------------------------- In survival_2.36-12 (and earlier), in the function cox_callback() at cox_Rcallback.c:40: PROTECT(coxlist=eval(lang2(fexpr,data),rho)); the return value of the call to lang2() is vulnerable if allocations within eval() give rise to garbage collection. (Discovered during CXXR development.) Andrew
2009 Aug 25
2
Clarifications please.
...yEval. 2) What exactly does install do? 3) I wrote the following code: #include <Rinternals.h> #include <Rembedded.h> int main (int argc, char** argv) { SEXP e,val; int errorOccurred; Rf_initEmbeddedR(argc, argv); // library("fPortfolio") PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // colMeans(SWX.RET) PROTECT(e = lang2(install("colMeans"), install("SWX.RET"))); val = (R_tryEval(e, NULL, &errorOccurred)); Rf_PrintVal...
2009 Sep 16
2
I want to get a reference to this time series object
...include <Rdefines.h> #include <Rembedded.h> int main(int argc, char** argv) { 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...
2020 Jun 30
2
Build a R call at C level
Hi All, I was reading the R extension manual section 5.11 ( Evaluating 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.1...
2019 May 01
3
anyNA() performance on vectors of POSIXct
...P args, SEXP env) { SEXP x = CAR(args); SEXPTYPE xT = TYPEOF(x); Rboolean isList = (xT == VECSXP || xT == LISTSXP), recursive = FALSE; if (isList && length(args) > 1) recursive = asLogical(CADR(args)); *if (OBJECT(x) || (isList && !recursive)) {* SEXP e0 = PROTECT(lang2(install("is.na"), x)); SEXP e = PROTECT(lang2(install("any"), e0)); SEXP res = PROTECT(eval(e, env)); int ans = asLogical(res); UNPROTECT(3); return ans == 1; // so NA answer is false. } R_xlen_t i, n = xlength(x); switch (xT) { case REALSXP: {...
2020 Jun 30
3
Build a R call at C level
...Still R-package-devel mailing list should be preferred for this kind > of questions. > Not sure if that is the best way, but works. > > call_to_sum <- inline::cfunction( > language = "C", > sig = c(x = "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; > > &quo...
2009 Sep 29
3
How do I access class slots from C?
...embedded.h> int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,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...
2003 Jan 16
1
Calling R function from within C code
Dear R experts, I'd like to call R function from within C code. I looked through the 'R exts' manual, found examples with lang2(R_fcall, list), and tried it, but it seemed to create the call, which can accept only a single argument of 'list' type, when I need to create the call of R functions with arbitrary numbers of arguments. How can I do it? Thanks a lot. -- WBR, Timur.
2006 Oct 22
1
Getting hold of a package's environment from C code
...I construct the call using lang1(install("foo")), but to eval it I need the package's environment. Is there a way to do this? Passing the correct environment through .Call() is not an option. Right now, I'm getting the environment first using something like rho = PROTECT(eval(lang2(install("environment"), install("bar")), R_GlobalEnv)) where bar _is_ exported. However, this doesn't work if the package is loaded but not attached, and is also risky because someone might define another "bar" that is found first. One solution that might work is...
2009 Oct 29
2
Help with lang4
Hi I seem to have run into a situation where I have more than 3 arguments to pass to a function from C. the following functions help me build an expression for evaluation: lang lang2 lang3 lang4 What should one do if there are more arguments than lang4 can handle? Regards Abhijit Bera [[alternative HTML version deleted]]
2020 Mar 23
5
help with rchk warnings on Rf_eval(Rf_lang2(...))
Thanks, that's really useful. One more question for you, or someone else here: const ArrayXd glmLink::linkFun(const ArrayXd& mu) const { return as<ArrayXd>(::Rf_eval(::Rf_lang2(as<SEXP>(d_linkFun), as<SEXP>(Rcpp::NumericVector(mu.data(), mu.data() + mu.size())) ), d_rho); } I guess I need that to read PROTECT(::Rf_eval(PROTECT(::Rf_lang2(...),...) , but as written it doesn't seem I have anywhere to squeeze in an UNPROTECT(2). Do I need...
2011 Mar 04
2
Fixing the HDF5 package: the on.exit mystery
...th, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) errorcall (call, "unable to open HDF file: %s", path); setup_onexit (fid, env); /* Messy code to walk tree structure of file snipped */ } /* The following function shown in its entirety */ setup_onexit (hid_t fid, SEXP env) { eval (lang2 (install ("on.exit"), lang2 (install ("hdf5cleanup"), ScalarInteger (fid))), env); } SEXP do_hdf5cleanup (SEXP args) { /* Code to process args snipped */ /* various cleanup things done including this: */ H5Fclose(fid) } /*--------...
2020 Mar 23
2
help with rchk warnings on Rf_eval(Rf_lang2(...))
...ilar to me, and that are now being flagged as problematic by Tomas Kalibera's 'rchk' machinery (https://github.com/kalibera/rchk); results are here https://raw.githubusercontent.com/kalibera/cran-checks/master/rchk/results/lme4.out The problem is with constructions like ::Rf_eval(::Rf_lang2(fun, arg), d_rho) I *think* this means "construct a two-element pairlist from fun and arg, then evaluate it within expression d_rho" This leads to warnings like "calling allocating function Rf_eval with argument allocated using Rf_lang2" Is this a false positive or ... ? Can...
2011 Jan 26
2
Dealing with R list objects in C/C++
...REAL(arg)[1] = 2.5; // control never reached here VECTOR_PTR(arg)[2] = allocVector(REALSXP, 4); REAL(VECTOR_PTR(arg)[2])[0] = 10.0; REAL(VECTOR_PTR(arg)[2])[1] = 11.0; REAL(VECTOR_PTR(arg)[2])[2] = 12.0; REAL(VECTOR_PTR(arg)[2])[3] = 13.0; PROTECT(call = lang2(install(entryPoint.c_str()), arg)); ret = R_tryEval(call, R_GlobalEnv, &errorOccurred); I'll be grateful if you can point me to any online docs/samples. Thanks in advance, Wayne _______________________________________________ This e-mail may contain information that is confidential, p...
2020 Jun 30
0
Build a R call at C level
...entation on R C api could be improved... Still R-package-devel mailing list should be preferred for this kind of questions. Not sure if that is the best way, but works. call_to_sum <- inline::cfunction( language = "C", sig = c(x = "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 3...
2020 Jun 30
0
Build a R call at C level
...ld be preferred for this kind > > of questions. > > Not sure if that is the best way, but works. > > > > call_to_sum <- inline::cfunction( > > language = "C", > > sig = c(x = "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); &...
2010 Sep 09
0
calling Rf_initEmbeddedR error
...ith: try { int Argc1 = 1; char *Argv1[] = {"Rtest_1"}; int 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...
2019 May 21
0
anyNA() performance on vectors of POSIXct
...CAR(args); > SEXPTYPE xT = TYPEOF(x); > Rboolean isList = (xT == VECSXP || xT == LISTSXP), recursive = FALSE; > > if (isList && length(args) > 1) recursive = asLogical(CADR(args)); > *if (OBJECT(x) || (isList && !recursive)) {* > SEXP e0 = PROTECT(lang2(install("is.na"), x)); > SEXP e = PROTECT(lang2(install("any"), e0)); > SEXP res = PROTECT(eval(e, env)); > int ans = asLogical(res); > UNPROTECT(3); > return ans == 1; // so NA answer is false. > } > > R_xlen_t i, n = xlength(x);...