search for: scalarr

Displaying 12 results from an estimated 12 matches for "scalarr".

Did you mean: scalar
2014 Oct 31
3
ScalarLogical and setAttrib
...o return the attribute: > test1() [1] FALSE > test2() [1] FALSE attr(,"foo") [1] "bar" > test1() [1] FALSE attr(,"foo") [1] "bar" It seems like ScalarLogical returns a singleton object, which is not the case for ScalarInteger or ScalarReal. I am currently working around this using duplicate(ScalarLogical(0)), but was quite surprised by this behavior of ScalarLogical.
2004 Mar 17
1
best methods for strings and structures?
...ScalarInteger( cfg_rec.endemic_mortality ) ); SET_VECTOR_ELT( ret_val, 5, ScalarInteger( cfg_rec.sdi_mortality ) ); SET_VECTOR_ELT( ret_val, 6, ScalarInteger( cfg_rec.file_in_format ) ); SET_VECTOR_ELT( ret_val, 7, ScalarInteger( cfg_rec.file_out_format ) ); SET_VECTOR_ELT( ret_val, 8, ScalarReal( cfg_rec.fixed_plot_radius ) ); SET_VECTOR_ELT( ret_val, 9, ScalarReal( cfg_rec.min_prism_dbh ) ); SET_VECTOR_ELT( ret_val, 10, ScalarReal( cfg_rec.baf ) ); SET_VECTOR_ELT( ret_val, 11, ScalarInteger( cfg_rec.max_sample_size ) ); SET_VECTOR_ELT( ret_val, 12, ScalarInteger( cfg_rec.us...
2015 Jun 01
2
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
...39; example: > sum2 <- inline::cfunction(sig=c(x="double", narm="logical"), body=' double *x_ = REAL(x); int narm_ = asLogical(narm); int n = length(x); double sum = 0; for (R_xlen_t i = 0; i < n; i++) { if (!narm_ || !ISNAN(x_[i])) sum += x_[i]; } return ScalarReal(sum); ') > x <- rep(0, 1e8) > stopifnot(typeof(x) == "double") > system.time(sum2(x, narm=FALSE)) user system elapsed 0.16 0.00 0.16 > y <- rep(NA_real_, 1e8) > stopifnot(typeof(y) == "double") > system.time(sum2(y, narm=FALSE)) u...
2008 Feb 27
1
Warnings generated by log2()/log10() are really large/takes a long time to display
x <- rnorm(1e6); y <- log(x); # or logb(x) or log1p(x) w <- warnings(); print(object.size(w)); ## [1] 480 str(w); $ NaNs produced: language log(x) - attr(*, "dots")= list() - attr(*, "class")= chr "warnings" y <- log2(x); # or log10(x) w <- warnings(); print(object.size(w)); ## [1] 8000536 str(w); ## List of 1 ## $ NaNs produced: language
2010 Jan 14
1
how to call a function from C
...generate a call with the function as the first node and then evaluate the call. SEXP stats = PROTECT( R_FindNamespace( mkString( "stats") ) ); SEXP rnorm = PROTECT( findVarInFrame( stats, install( "rnorm") ) ) ; SEXP call = PROTECT( LCONS( rnorm, CONS( ScalarInteger(10), CONS(ScalarReal(0), R_NilValue ) ) ) ); SEXP res = PROTECT( eval( call , R_GlobalEnv ) ); UNPROTECT(4) ; return res ; It works, but I was wondering if there was another way. I've seen applyClosure, but I'm not sure I should attempt to use it or if using a call like above is good enough. Romain PS:...
2020 May 22
0
round() and signif() do not check argument names when a single argument is given
...thmetic.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 here, and then this g...
2015 Jun 01
0
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
...nline::cfunction(sig=c(x="double", narm="logical"), body=' #define LDOUBLE long double double *x_ = REAL(x); int narm_ = asLogical(narm); int n = length(x); LDOUBLE sum = 0.0; for (R_xlen_t i = 0; i < n; i++) { if (!narm_ || !ISNAN(x_[i])) sum += x_[i]; } return ScalarReal((double)sum); ') > x <- rep(0, 1e8) > stopifnot(typeof(x) == "double") > system.time(sum3(x, narm=FALSE)) user system elapsed 0.40 0.00 0.44 > y <- rep(NA_real_, 1e8) > stopifnot(typeof(y) == "double") > system.time(sum3(y, narm=FALSE...
2007 Jun 08
1
Question about Running C code from R
...the C code (simplecall.c): *********************************************************************************************** #include <stdio.h> #include <Rinternals.h> #include <R_ext/Rdynload.h> int Rc(int a) { return (a+3); } SEXP Rc2(SEXP a) { return(18); //LINE A // return(ScalarReal(REAL(a)[0]+12)); //LINE B } int main() { int i,j; SEXP m,n; i=4;j=Rc(i); printf("\nUsing Rc: %i+3=%i - OK so far.\n",i,j); m=6;n=Rc2(m); printf("\nUsing Rc2: %i+12=%i - Doing well.\n",m,n); printf("\nPress <ENTER> ...\n"); getchar(); return 0; } *...
2007 Mar 27
3
Use of 'defineVar' and 'install' in .Call
Dear all, [system and version information below] I am trying to modify a C function for finding the root of an expression. The function is to be called from R as .Call with input parameters: f: expression for which we will find the root guesses: interval for the solution stol: tolerance rho: environment The original functions I use are: SEXP mkans(double x) { SEXP ans; PROTECT(ans =
2007 Mar 27
3
Use of 'defineVar' and 'install' in .Call
Dear all, [system and version information below] I am trying to modify a C function for finding the root of an expression. The function is to be called from R as .Call with input parameters: f: expression for which we will find the root guesses: interval for the solution stol: tolerance rho: environment The original functions I use are: SEXP mkans(double x) { SEXP ans; PROTECT(ans =
2011 Jan 26
2
Dealing with R list objects in C/C++
Hi, I'd like to construct an R list object in C++, fill it with relevant data, and pass it to an R function which will return a different list object back. I have browsed through all the R manuals, and examples under tests/Embedding, but can't figure out the correct way. Below is my code snippet: #include <Rinternals.h> // Rf_initEmbeddedR and other setups already performed
2014 Mar 05
1
[PATCH] Code coverage support proof of concept
...R_Cov_freqs_hash); + + /* put the params nb_lines and growth_rate as hidden vars of the hashed env */ + R_Cov_freqs_hash = R_NewHashedEnv(R_NilValue, ScalarInteger(0)); + PROTECT(sexp = ScalarInteger(nb_lines)); + defineVar(install(".nb_lines"), sexp, R_Cov_freqs_hash); + + PROTECT(sexp = ScalarReal(growth_rate)); + defineVar(install(".growth_rate"), sexp, R_Cov_freqs_hash); + + R_PreserveObject(R_Cov_freqs_hash); +} + +/* Ends the code coverage tracing. + * and returns an environment with symbols named after the covered source files and values + * matrices of dim n*2, which first...