search for: scalarlogical

Displaying 20 results from an estimated 31 matches for "scalarlogical".

2014 Oct 31
3
ScalarLogical and setAttrib
Is it expected that attributes set on a LGLSXP created by ScalarLogical will apply to all future objects created by ScalarLogical as well? For example: the 'test1' function below returns FALSE and 'test2' returns FALSE with an attribute: library(inline) test1 <- cfunction(body = 'return ScalarLogical(0);') test2 <- cfunction(body =...
2019 Jan 05
1
unsorted - suggestion for performance improvement and ALTREP support for POSIXct
...rt() (sort.c line 401). The example below shows the performance improvement for a vectors of double of moving REAL() outside the for loop. # example as implemented in isUnsorted body = " R_xlen_t n, i; n = XLENGTH(x); for(i = 0; i+1 < n ; i++) if(REAL(x)[i] > REAL(x)[i+1]) return ScalarLogical(TRUE); return ScalarLogical(FALSE);"; f1 = inline::cfunction(sig = signature(x='numeric'), body=body) # example updated with only one call to REAL() body = " R_xlen_t n, i; n = XLENGTH(x); double* real_x = REAL(x); for(i = 0; i+1 < n ; i++) if(real_x[i] > real_x[i+1])...
2006 May 14
1
bindingIsLocked returns illogical logical
bindingIsLocked applied to a locked binding returns a 'logical' that is niether true nor false. Martin > e <- new.env() > e$x <- 1 > e$y <- 2 > lockBinding("x", e) NULL > bindingIsLocked("x", e) [1] TRUE > bindingIsLocked("x", e)==TRUE [1] FALSE > bindingIsLocked("x", e)==FALSE [1] FALSE >
2017 Mar 03
2
Control statements with condition with greater than one should give error (not just warning) [PATCH]
...s" @@ -248,9 +249,9 @@ char *p; #ifdef HAVE_RL_COMPLETION_MATCHES + PROTECT(v = val = allocList(22)); +#else PROTECT(v = val = allocList(21)); -#else - PROTECT(v = val = allocList(20)); #endif SET_TAG(v, install("prompt")); @@ -289,6 +290,10 @@ SETCAR(v, ScalarLogical(0)); /* no checking */ v = CDR(v); + SET_TAG(v, install("check.condition")); + SETCAR(v, ScalarLogical(0)); /* no checking */ + v = CDR(v); + p = getenv("R_KEEP_PKG_SOURCE"); R_KeepSource = (p && (strcmp(p, "yes") == 0)) ? 1 : 0; I...
2017 Mar 03
0
Control statements with condition with greater than one should give error (not just warning) [PATCH]
...TION_MATCHES > + PROTECT(v = val = allocList(22)); > +#else > PROTECT(v = val = allocList(21)); > -#else > - PROTECT(v = val = allocList(20)); > #endif > SET_TAG(v, install("prompt")); > @@ -289,6 +290,10 @@ > SETCAR(v, ScalarLogical(0)); /* no checking */ > v = CDR(v); > + SET_TAG(v, install("check.condition")); > + SETCAR(v, ScalarLogical(0)); /* no checking */ > + v = CDR(v); > + > p = getenv("R_KEEP_PKG_SOURCE"); > R_KeepSource = (p && (s...
2013 May 09
0
cairo is not the default when available
...se "Xlib") and if (.Platform$OS.type != "windows" && !.Call(C_cairoProps, 2L)) X11.options(type = "Xlib") cairoProps is in src/library/grDevices/src/init.c: static SEXP cairoProps(SEXP in) { int which = asInteger(in); if(which == 1) return ScalarLogical( #ifdef HAVE_WORKING_CAIRO 1 #else 0 #endif ); else if(which == 2) return ScalarLogical( #ifdef HAVE_PANGOCAIRO 1 #else 0 #endif ); return R_NilValue; } I believe this is where the problem comes in. I don't have pangocairo and cairoPr...
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...
2020 Jun 30
3
Build a R call at C level
...gt; 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...
2017 Mar 03
2
Control statements with condition with greater than one should give error (not just warning) [PATCH]
...allocList(22)); > > +#else > > PROTECT(v = val = allocList(21)); > > -#else > > - PROTECT(v = val = allocList(20)); > > #endif > > > SET_TAG(v, install("prompt")); > > @@ -289,6 +290,10 @@ > > SETCAR(v, ScalarLogical(0)); /* no checking */ > > v = CDR(v); > > > + SET_TAG(v, install("check.condition")); > > + SETCAR(v, ScalarLogical(0)); /* no checking */ > > + v = CDR(v); > > + > > p = getenv("R_KEEP_PKG_SOURCE"); >...
2018 Mar 18
3
`@<-` modify its argument when slot is externalptr
Dear all, I am confused about the inconsistent behaviors of `@<-` operator when used in different ways. Consider the following example: library(inline) # Function to generate an externalptr object with random address new_extptr <- cfunction(c(), ' SEXP val = PROTECT(ScalarLogical(1)); SEXP out = PROTECT(R_MakeExternalPtr(&val, R_NilValue, val)); UNPROTECT(2); return(out); ') setClass("S4ClassHoldingExtptr", contains = "externalptr") subs_extptr_1 <- function(x) { x at .xData <- new_extptr() x } subs_extptr_2...
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
2017 Jan 25
2
parallel::mc*: Is it possible for a child process to know it is a fork?
When using multicore-forking of the parallel package, is it possible for a child process to know that it is a fork? Something like: parallel::mclapply(1:10, FUN = function(i) { test_if_running_in_a_fork() }) I'm looking into ways to protect against further parallel processes (including threads), which not necessarily are created via the parallel:mc* API, are being spawned off recursively.
2017 Jan 25
0
parallel::mc*: Is it possible for a child process to know it is a fork?
..., is it possible > for a child process to know that it is a fork? R internally uses R_isForkedChild to prevent certain operations within the fork. However I don't think this is exported anywhere. You could do something like: extern Rboolean R_isForkedChild; SEXP is_forked(){ return ScalarLogical(R_isForkedChild); } But that won't be allowed on CRAN: * checking compiled code ... NOTE Found non-API call to R: ?R_isForkedChild? Compiled code should not call non-API entry points in R. Another method would be to look at getppid(2) and getpgid(2) to lookup the parent-id and group-id...
2020 Jun 30
0
Build a R call at C level
...ling 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 30, 2020 at 10:08 AM Morgan Morgan <morgan.emailbox at gmail.com> wro...
2020 Jun 30
0
Build a R call at C level
...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(1...
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
2023 Apr 14
0
sum(), min(), max(), prod() vs. named arguments in ...
...ay: --- src/main/summary.c (revision 84252) +++ src/main/summary.c (working copy) @@ -409,6 +409,7 @@ attribute_hidden SEXP fixup_NaRm(SEXP args) { + Rboolean seen_NaRm = FALSE; SEXP t, na_value; /* Need to make sure na.rm is last and exists */ @@ -415,7 +416,9 @@ na_value = ScalarLogical(FALSE); for(SEXP a = args, prev = R_NilValue; a != R_NilValue; a = CDR(a)) { if(TAG(a) == R_NaRmSymbol) { + if(seen_NaRm) error("Please specify na.rm only once"); + seen_NaRm = TRUE; if(CDR(a) == R_NilValue) return args; na_value = CAR(a); if(prev == R_Nil...
2018 Mar 18
0
`@<-` modify its argument when slot is externalptr
...fused about the inconsistent behaviors of `@<-` operator when > used in different ways. Consider the following example: > > library(inline) > > # Function to generate an externalptr object with random address > new_extptr <- cfunction(c(), ' > SEXP val = PROTECT(ScalarLogical(1)); > SEXP out = PROTECT(R_MakeExternalPtr(&val, R_NilValue, val)); > UNPROTECT(2); > return(out); > ') > > setClass("S4ClassHoldingExtptr", contains = "externalptr") > > subs_extptr_1 <- function(x) { > x at .xData <- new...
2014 Jun 17
0
PATCH: Avoiding extra copies (NAMED bumped) with source(..., print.eval=FALSE) ...and with print.eval=TRUE?
...R(args); x = eval(x, rho); PROTECT(x); PROTECT(ret = allocVector(VECSXP, 2)); PROTECT(nm = allocVector(STRSXP, 2)); SET_STRING_ELT(nm, 0, mkChar("value")); SET_STRING_ELT(nm, 1, mkChar("visible")); SET_VECTOR_ELT(ret, 0, x); SET_VECTOR_ELT(ret, 1, ScalarLogical(R_Visible)); setAttrib(ret, R_NamesSymbol, nm); UNPROTECT(3); return ret; } Not sure exactly where the reference count (NAMED is updated) is bumped, but *if it is possible to evaluate the expression and inspect if the value is "visible" or not before it happens*, then one cou...
2023 Apr 16
0
sum(), min(), max(), prod() vs. named arguments in ...
.../summary.c (working copy) > @@ -409,6 +409,7 @@ > attribute_hidden > SEXP fixup_NaRm(SEXP args) > { > + Rboolean seen_NaRm = FALSE; > SEXP t, na_value; > > /* Need to make sure na.rm is last and exists */ > @@ -415,7 +416,9 @@ > na_value = ScalarLogical(FALSE); > for(SEXP a = args, prev = R_NilValue; a != R_NilValue; a = CDR(a)) { > if(TAG(a) == R_NaRmSymbol) { > + if(seen_NaRm) error("Please specify na.rm only once"); > + seen_NaRm = TRUE; > if(CDR(a) == R_NilValue) return args; > na_valu...