search for: setcdr

Displaying 17 results from an estimated 17 matches for "setcdr".

Did you mean: setcar
2010 Aug 21
1
Speed improvement to evalList
...; } ev = CONS(eval(CAR(h), rho), R_NilValue); COPY_TAG(ev, h); if (mode==0) { head = ev; mode = 1; } else { SETCDR(tail, ev); } tail = ev; h = CDR(h); } } else if (h != R_MissingArg) error(_("'...' used in an incorrect context")); } else if (CAR(el) == R_MissingArg) { /* It was an empty element: most likely get here from evalArg...
2020 Jun 30
3
Build a R call at C level
...at 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 30, 2020 at 10:08 AM Morgan Morgan > <morg...
2020 Sep 11
4
Garbage collection of seemingly PROTECTed pairlist
...SEXP row = PROTECT(C_int_mat_nth_row_nrnc(int_mat_int, nr, 2, row_num)); Rf_PrintValue(prlst); // This is where the error occurs int *row_int = INTEGER(row); if (row_int[0] == last + 1) { Rprintf("here1"); SEXP next = PROTECT(Rf_list1(row)); prlst_tail = SETCDR(prlst_tail, next); last = row_int[1]; UNPROTECT(1); ++row_num; } else { Rprintf("here2"); SEXP next_car = PROTECT(C_make_len2_int_vec(last + 1, row_int[0] - 1)); SEXP next = PROTECT(Rf_list1(next_car)); prlst_tail = SETCDR(prlst_tail, next);...
2020 May 22
0
round() and signif() do not check argument names when a single argument is given
...on in src/main/arithmetic.c: do_Math2(). The strange cases get handled by the code around line 1655 in src/main/arithmetic.c. The context is n is the number of arguments, but symbol names have not yet been checked: if(n == 1) { double digits = 0.0; if(PRIMVAL(op) == 10004) digits = 6.0; SETCDR(args, CONS(ScalarReal(digits), R_NilValue)); } Here, 10004 is the opcode symbol for signif and 10001 is for round, but these are the only two ops handled by this function, so round uses digits=0.0. The SETCDR creates the argument list to be the current 1-item list plus the new digits value set he...
2020 Jun 30
0
Build a R call at C level
Thanks Jan and Tomas for the feedback. Answer from Jan is what I am looking for. Maybe I am not looking in the right place buy it is not easy to understand how these LCONS, CONS, SETCDR...etc works. Thank you Best regards Morgan On Tue, 30 Jun 2020, 12:36 Tomas Kalibera, <tomas.kalibera at gmail.com> wrote: > On 6/30/20 1:06 PM, Jan Gorecki wrote: > > It is quite known that R documentation on R C api could be improved... > > Please see "5.11 Evaluati...
2023 Apr 14
0
sum(), min(), max(), prod() vs. named arguments in ...
...ively safe to make it a warning to pass named arguments to sum() that are not na.rm and later transition it to an error: --- src/main/summary.c (revision 84252) +++ src/main/summary.c (working copy) @@ -419,6 +419,8 @@ na_value = CAR(a); if(prev == R_NilValue) args = CDR(a); else SETCDR(prev, CDR(a)); + } else if (TAG(a) && TAG(a) != R_NilValue) { + warning("Named argument \"%s\" here is probably a mistake", CHAR(PRINTNAME(TAG(a)))); } prev = a; } (Can TAG(a) ever be NULL or anything other than R_NilValue or a symbol here? We'll probab...
2020 Sep 12
0
Garbage collection of seemingly PROTECTed pairlist
...h_row_nrnc(int_mat_int, nr, 2, > row_num)); > Rf_PrintValue(prlst); // This is where the error occurs > int *row_int = INTEGER(row); > if (row_int[0] == last + 1) { > Rprintf("here1"); > SEXP next = PROTECT(Rf_list1(row)); > prlst_tail = SETCDR(prlst_tail, next); > last = row_int[1]; > UNPROTECT(1); > ++row_num; > } else { > Rprintf("here2"); > SEXP next_car = PROTECT(C_make_len2_int_vec(last + 1, row_int[0] - > 1)); > SEXP next = PROTECT(Rf_list1(next_car)); >...
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
2023 Apr 16
0
sum(), min(), max(), prod() vs. named arguments in ...
...d be quite intrusive, since it is not uncommon to see do.call(sum, <named list>). > --- src/main/summary.c (revision 84252) > +++ src/main/summary.c (working copy) > @@ -419,6 +419,8 @@ > na_value = CAR(a); > if(prev == R_NilValue) args = CDR(a); > else SETCDR(prev, CDR(a)); > + } else if (TAG(a) && TAG(a) != R_NilValue) { > + warning("Named argument \"%s\" here is probably a mistake", CHAR(PRINTNAME(TAG(a)))); > } > prev = a; > } > > (Can TAG(a) ever be NULL or anything other than R_NilVa...
2020 Jun 30
0
Build a R call at C level
...r 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 30, 2020 at 10:08 AM Morgan Morgan <morgan.emailbox at gmail.com> wrote: > > Hi All, &gt...
2008 Mar 29
0
"Writing R Extensions": bad example with CAR / CDR as lvalues (PR#11054)
...ave spotted immediatly) that the example is taken from a code snipped that imports Rinternals.h with defined USE_RINTERNALS, while I followed the manual's advice to not define USE_RINTERNALS for extensions. Maybe you could add a note in this section of the manual that one should use SETCAR and SETCDR instead. A more illustrative example would be even better. Just in case you want to use it as example, here is my code. I hope it is correct in your expert eyes. /* Remove the variable with name s from the environment ev, i.e. construct the call: rm( list=s, envir=ev ) */ SEXP call...
2008 Mar 31
1
(PR#11054) "Writing R Extensions": bad example with CAR /
...that the example is taken from a code snipped that imports > Rinternals.h with defined USE_RINTERNALS, while I followed the manual's advice > to not define USE_RINTERNALS for extensions. > > Maybe you could add a note in this section of the manual that one should use > SETCAR and SETCDR instead. A more illustrative example would be even better. > > > Just in case you want to use it as example, here is my code. I hope it is > correct in your expert eyes. > > /* Remove the variable with name s from the environment ev, > i.e. construct the call: rm( list=s...
2006 Sep 08
1
R drop behavior -- set as option in later version?
...tted must be the first argument. */ static void ExtractDropArg(SEXP el, int *drop) { SEXP last = el; for (el = CDR(el); el != R_NilValue; el = CDR(el)) { if(TAG(el) == R_DropSymbol) { *drop = asLogical(CAR(el)); if (*drop == NA_LOGICAL) *drop = 1; SETCDR(last, CDR(el)); } else last = el; } } ------------ This is not exactly the right syntax for a GetOption call, but something along the following lines should allow globally settable drop by modifying line 505: ------------ if(*drop == NA_LOGICAL) { GetOption("GlobalD...
2006 Sep 08
1
R drop behavior -- set as option in later version?
...tted must be the first argument. */ static void ExtractDropArg(SEXP el, int *drop) { SEXP last = el; for (el = CDR(el); el != R_NilValue; el = CDR(el)) { if(TAG(el) == R_DropSymbol) { *drop = asLogical(CAR(el)); if (*drop == NA_LOGICAL) *drop = 1; SETCDR(last, CDR(el)); } else last = el; } } ------------ This is not exactly the right syntax for a GetOption call, but something along the following lines should allow globally settable drop by modifying line 505: ------------ if(*drop == NA_LOGICAL) { GetOption("GlobalD...
2012 Aug 09
4
debug vs regular mode
Dear all, I had a R segmentation fault, and then invoked debug mode and ran step by step. When I reached "terms(Y~X1*X2*...*X16)", I would then have "segmentation" fault. However, if I just ran this under regular "R interactive" mode, it would be fine though taking long time. My questions are: 1. Is there a known limit of terms for a formula? 2. Why does the
2012 Aug 09
4
debug vs regular mode
Dear all, I had a R segmentation fault, and then invoked debug mode and ran step by step. When I reached "terms(Y~X1*X2*...*X16)", I would then have "segmentation" fault. However, if I just ran this under regular "R interactive" mode, it would be fine though taking long time. My questions are: 1. Is there a known limit of terms for a formula? 2. Why does the
2002 Jul 11
1
dyn.load tcl/tk (PR#1774)
...v R_NilValue R_NaString Rf_coerceVector Rf_PairToVectorList Rf_VectorToPairList Rf_allocString Rf_allocVector Rf_allocList Rf_asInteger Rf_duplicate Rf_GetOption Rf_install Rf_isList Rf_isVector Rf_length Rf_listAppend Rf_nthcdr Rf_PrintDefaults Rf_protect Rf_unprotect SET_STRING_ELT SET_TAG SETCAR SETCDR Rf_begincontext Rf_endcontext Rf_str2type Rf_errorcall Rf_EncodeElement vmaxget vmaxset R_alloc Rprintf Rf_elt Rf_findVar Rf_GetDevice devNumber GEplayDisplayList addInputHandler getInputHandler removeInputHandler R_InputHandlers Rf_KillDevice R_setX11Routines gmake[5]: Entering directory `/soft/R/...