Displaying 8 results from an estimated 8 matches for "setcadr".
2003 Nov 03
2
lang2(...) with two and more arguments
...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);
SETCADR(R_fcall, y);
UNPROTECT(3);
return R_fcall;
}
.Call("f", c, new.env()) returns
`.Primitive("c")(20)', but not `.Primitive("c")(10, 20)',
as I expected. How can I recieve the disired result?
Thank you very much.
--
WBR,
Timu...
2019 Sep 27
2
Evaluate part of an expression at C level
Hi,
I am wondering if the below is possible?
Let's assume I have the following expression:
1:10 < 5
Is there a way at the R C API level to only evaluate the 5th element (i.e 5
< 5) instead of evaluating the whole expression and then select the 5th
element in the logical vector?
Thank you
Best regards
Morgan
[[alternative HTML version deleted]]
2009 May 26
1
passing "..." arguments to a function called by eval()
...in pkg/src directory
SEXP dTestC(SEXP dblX, SEXP funFn, SEXP dots, SEXP rho);
/*--------------------------*/
SEXP dTestC(SEXP dblX, SEXP funFn, SEXP dots, SEXP rho){
SEXP retVal;
SEXP R_fcall;
PROTECT(retVal = NEW_NUMERIC(1));
PROTECT(R_fcall = lang3(funFn, R_NilValue, R_NilValue));
SETCADR(R_fcall, dblX);
SETCADDR(R_fcall, dots);
retVal = eval(R_fcall, rho);
UNPROTECT(2);
return(retVal);
}
########################
When I call the dTest() function, the first required argument and the
first optional argument are both used, but not the ones after that.
I'm modeling thi...
2008 Apr 24
1
Calling R functions with multiple arguments from C
...SEXP elmt1, SEXP elmt2, SEXP rho)
{
SEXP R_fcall, args, ans,s;
PROTECT( args = s = allocList(2));
PROTECT( R_fcall = lang2(fn, R_NilValue) );
SETCAR(s,elmt1);
SET_TAG(s,install("x"));
s = CDR(s);
SETCAR(s,elmt2);
SET_TAG(s,install("y"));
SETCADR( R_fcall, args);
PROTECT( ans = eval(R_fcall, rho) );
UNPROTECT(3);
return ans;
}
foo.func <- function(x,y)match.call()
>.Call("foo",foo.func,x=10,y=12,new.env())
function(x,y)match.call()
(x = list(x = 10, y = 12))
> sessionInfo()
R version 2.7.0 (2008-04...
2004 Feb 17
2
interfacing C++ using .Call
...`Rf_setAttrib(SEXPREC*, SEXPREC*, SEXPREC*)'
test.a(test.o.b)(.text+0x113):test.cpp: undefined reference to
`Rf_unprotect(int)'
test.a(test.o.b)(.text+0x129):test.cpp: undefined reference to
`VECTOR_ELT(SEXPREC*, int)'
test.a(test.o.b)(.text+0x132):test.cpp: undefined reference to
`SETCADR(SEXPREC*, SEXPREC*)'
test.a(test.o.b)(.text+0x13e):test.cpp: undefined reference to
`Rf_eval(SEXPREC*, SEXPREC*)'
test.a(test.o.b)(.text+0x14a):test.cpp: undefined reference to
`SET_VECTOR_ELT(SEXPREC*, int, SEXPREC*)'
make: *** [test.dll] Error 1
Adding extern "C" {} does...
2007 Apr 13
1
Simulated annealing using optim()
I'm preparing some code to compute the optimal geometry of stressed
solids. The core of the calculations is the optimization of elastic energy
using the simulated annealing method implemented in the R optim() rutine.
I've defined a function to compute this "energy" scalar (the fn parameter
for optim) and prepared a list with the arrays defining the geometry and
the elastic
2008 Jun 18
2
embedding R in c++ (Qt) application
Hi R-Developers,
I'm working on running statistical analyses with embedded R from a
Qt-GUI-application (C++).
I've been able to link with R libraries, but I'm having a hard time to
understand the C-coding examples. I'm a C++, not a C programmer (never
used malloc before), and many of the R-specific
functions/keywords/macros (for instance (UN)PROTECT, SETCAR, all the
2008 Apr 29
2
Calling R from C - part way there but need a push!
Dear All,
I've read the manual on "Writing R Extensions" and in particular the
part on calling R from C. (Most of the manual is about calling C
from R, not the other way around.)
The good news is that I can now call _some_ R from C, specifically
the R functions which have C header files. However it isn't clear to
me how to call R functions that are written in R. I