search for: new_numeric

Displaying 20 results from an estimated 22 matches for "new_numeric".

2004 Jun 30
1
AS_NUMERIC and as.numeric - Could someone explain?
...EXP hyp2f1forrey(SEXP a, SEXP b, SEXP c, SEXP x) { int i,n; double *xa, *xb, *xc, *xx, *xresr, *xresi; SEXP resr, resi; n = LENGTH(a); PROTECT(a = AS_NUMERIC(a)); PROTECT(b = AS_NUMERIC(b)); PROTECT(c = AS_NUMERIC(c)); PROTECT(x = AS_NUMERIC(x)); PROTECT(resr = NEW_NUMERIC(n)); PROTECT(resi = NEW_NUMERIC(n)); xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b); xc = NUMERIC_POINTER(c); xx = NUMERIC_POINTER(x); xresr = NUMERIC_POINTER(resr); xresi = NUMERIC_POINTER(resi); for (i = 0; i < n; i++) F77_CALL(hyp)(&xx[i], &...
2010 Jun 18
3
C interface
...simple C-code from R. I am on Windows XP with RTools installed. The C-function is #include <R.h> #include <Rinternals.h> #include <Rmath.h> #include <Rdefines.h> // prevent name mangling extern "C" { SEXP __cdecl test(SEXP s){ SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u>0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf("The value is %f", *ptr); UNPROTECT(1); return result; } }; It is compiled with R CMD SHLIB source.c with flag MAKEFLAGS="CC=...
2010 Jun 18
4
C Interface
...simple C-code from R. I am on Windows XP with RTools installed. The C-function is #include <R.h> #include <Rinternals.h> #include <Rmath.h> #include <Rdefines.h> // prevent name mangling extern "C" { SEXP __cdecl test(SEXP s){ SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u>0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf("The value is %f", *ptr); UNPROTECT(1); return result; } }; It is compiled with R CMD SHLIB OrthoFunctions.c with flag MAKEFLAGS=&...
2004 Feb 11
1
.Call setAttrib(ans,R_DimSymbol,dim); Crashes.
Hi! I want to return a matrix. The code does the R interfacing. This version does it fine. SEXP ans,dim; PROTECT(ans = NEW_NUMERIC(count*2)); memcpy(NUMERIC_POINTER(ans),result,count*sizeof(double)); memcpy(&(NUMERIC_POINTER(ans)[count]),occur,count*sizeof(double)); /** PROTECT(dim=NEW_INTEGER(2)); INTEGER_POINTER(dim)[0]=2; INTEGER_POINTER(dim)[1]=count; setAttrib(ans,R_DimSymbol,dim); */ UNPROTECT(7);...
2004 Feb 26
1
Handling R Objects in C
...icrosoft Visual C++.Net I put a multiproject solution,and one project is a win32 and dedicated for R manipulation; When I put in this project the example code from "Written R extension" 4.7 Handling R objects in C p39: #include <R.h> #include <Rdefines.h> SEXP ab; PROTECT(ab=NEW_NUMERIC(2)) ; .... I got an unresolved external in the link, because I don't know what I need to declare as an external library,I searched in the documentation but I didn't find Could you please help me Thank a lot by advance Pascal
2014 Sep 07
1
lbfgsb from C/C++
...nction from my C/C++ code by including R_ext/Applic.h and linking against libR. Currently, I am allocating memory for x (and the other input arrays for lbfgsb) in my C/C++ code via malloc/new. However, this gives a segmentation fault when executing the program. I tried to allocate x via PROTECT(x = NEW_NUMERIC(n)); x_p = NUMERIC_POINTER(x);. This compiles but also gives a segmentation fault. Is there a way to use lbfgsb from C/C++ directly (without an intermediate call of R)? Did I miss any compile flags? Thanks [[alternative HTML version deleted]]
2010 Jun 15
1
Error when callin g C-Code
...*xNT, *xtau; SEXP tau; int ltgrid =0; int i = 0; int j = 0; sign = 0; EVar = 0; ltgrid = LENGTH(tgrid); PROTECT(lambda = AS_NUMERIC(lambda)); PROTECT(tgrid = AS_NUMERIC(tgrid)); PROTECT(T2M = AS_NUMERIC(T2M)); PROTECT(Ni = AS_NUMERIC(Ni)); PROTECT(NT = AS_NUMERIC(NT)); PROTECT(tau = NEW_NUMERIC(1)); xlambda = NUMERIC_POINTER(lambda); xtgrid = NUMERIC_POINTER(tgrid); xT2M = NUMERIC_POINTER(T2M); xNi = NUMERIC_POINTER(Ni); xNT = NUMERIC_POINTER(NT); xtau = NUMERIC_POINTER(tau); GetRNGstate(); if(xlambda[0] != 0) { while(1) { EVar = rexp(xlambda[0]); sign = sign + EVar;...
2004 Jun 16
1
Compiling C++ package source: linking problem?
...<Rdefines.h> ... SEXP whatever (SEXP model) { Rprintf ("Hello, here I am!\n"); return model; } However, the following doesn't compile at all: #include <R.h> #include <Rdefines.h> ... SEXP whatever (SEXP model) { SEXP anotherModel; PROTECT(anotherModel = NEW_NUMERIC(4)); UNPROTECT(1); return anotherModel; } An example of compiler feedback from R CMD SHLIB (I have mingw 3.1.0): ...: undefined reference to 'Rf_allocVector(unsigned,int)' ...: undefined reference to 'Rf_protect(SEXPREC*)' ...: undefined reference to 'Rf_unprotect(int)...
2004 Jan 09
1
Call and memory
...t( SEXP Xi, SEXP Ni, SEXP ki ) { double *pX=NUMERIC_POINTER(Xi); int N=INTEGER_POINTER(Ni)[0]; int k=INTEGER_POINTER(ki)[0]; SEXP alist; SEXP avector; SEXP nvector; SEXP rvector; SEXP kvector; int n; int i; transposeMatrix(pX,N,k); n=4; PROTECT(alist=NEW_LIST(n)); PROTECT(avector=NEW_NUMERIC(200)); for (i=0;i<200;i++) { NUMERIC_POINTER(avector)[i]=pX[i]; } SET_ELEMENT(alist,0,avector); UNPROTECT(1); PROTECT(nvector=NEW_INTEGER(1)); INTEGER_POINTER(nvector)[0]=N; SET_ELEMENT(alist,1,nvector); UNPROTECT(1); PROTECT(rvector=NEW_NUMERIC(1)); NUMERIC_POINTER(rvector)[0]=0.5;...
2009 Apr 09
1
.Call()
...o.h> #include <R.h> #include <Rdefines.h> #include <math.h> SEXP ESscore(SEXP Rgeneset, SEXP Rgenemat, SEXP Rranklist, SEXP sim) { int nc = ncols(Rgenemat); double *geneset = NUMERIC_DATA(Rgeneset); double *genemat = NUMERIC_DATA(Rgenemat); SEXP Rscore; PROTECT(Rscore=NEW_NUMERIC(sim)); double *score = NUMERIC_DATA(Rscore); for(i=1; i<=sim; i++){ if(i>2) {genemat <- genemat[,sample(1:nc)];} for(k=1; k<nc ) } } [[alternative HTML version deleted]]
2003 May 21
2
moving onto returning a data.frame?
...so far... SEXP testfunction3( SEXP m_in ) { int *mdims, n, p, i; double *mm; SEXP m_out; SEXP nms; if( !isMatrix( m_in ) ) { error("m_in must be a matrix"); } mdims = INTEGER( GET_DIM( m_in ) ); n = mdims[0]; p = mdims[1]; PROTECT( m_out = NEW_NUMERIC( p ) ); PROTECT( m_in = AS_NUMERIC( m_in ) ); PROTECT( nms = GET_COLNAMES( GET_DIMNAMES( m_in ) ) ); /* here you'll disect the incoming data.frame into the vectors you'll pass into your simulation code */ /* get the vectors based on the column names to make sure the sequence...
2006 Aug 21
1
return tree from .Call
...e I was thinking about using to do this. Any suggestions or help will be greatly appreciated! SEXP list ; PROTECT( list = allocVector(VECSXP, tree->size) ) ; for( i = 0; i < tree->size; ++i ){ SEXP node, tree_double, tree_char, tree_int, tree_voidPTR ; PROTECT( tree_double = NEW_NUMERIC( tree->weight ) ) ; PROTECT( tree_char = NEW_CHARACTER( tree->name ) ) ; PROTECT( tree_int = NEW_INTEGER( tree->exons ) ) ; PROTECT( tree_voidPTR = NEW_CHARACTER( tree->data ) ) ; ??? not sure about this... PROTECT( node = allocVector( VECSXP, 4 ) ) ; SET_VEC...
2009 May 26
1
passing "..." arguments to a function called by eval()
...o=new.env(),PACKAGE="pkg") return(retVal) } ########## C code, 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...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
..._t i, j, na, nb, nab; double *xa, *xb, *xab; SEXP ab; PROTECT(a = AS_NUMERIC(a)); /* PJ wonders, doesn't this alter "a" in calling code*/ PROTECT(b = AS_NUMERIC(b)); na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1; PROTECT(ab = NEW_NUMERIC(nab)); xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b); xab = NUMERIC_POINTER(ab); for(i = 0; i < nab; i++) xab[i] = 0.0; for(i = 0; i < na; i++) for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j]; UNPROTECT(3); return(a...
2000 May 15
1
pythag missing in src/appl/ROUTINES (PR#544)
...quot;pythag") [1] FALSE ----------------------------------------- /* pythagtry.c */ #include <R.h> #include <Rdefines.h> #include <R_ext/Applic.h> SEXP pytry(SEXP x, SEXP y) { SEXP ans; double xa, xb; xa = NUMERIC_POINTER(x)[0]; xb = NUMERIC_POINTER(y)[0]; PROTECT(ans = NEW_NUMERIC(1)); NUMERIC_POINTER(ans)[0] = pythag(xa, xb); UNPROTECT(1); return(ans); } ------------------------------------------------------------- $ R_HOME=/usr/local/lib/R gcc -I/usr/local/lib/R/include -c pythagtry.c $ gcc -shared -o pythagtry.so pythagtry.o --------------------------------------------...
2006 Oct 31
1
Some R questions
Hi all, I am working with some large data sets (1-4 GB) and have some questions that I hope someone can help me with: 1. Is there a way to turn off garbage collector from within C interface ? what I am trying to do is suck data from mysql (using my own C functions) and I see that allocating each column (with about 1-4 million items) takes between 0.5 and 1 seconds. My
2000 May 04
2
alas, no vecnorm
I wanted a function that would give the euclidean distance of a vector. Then I was happy, because I found vecnorm listed on pg 55 of V&R (3rd edn) which I had just bought today. Then I was sad, because R did not have vecnorm. Then I was happy again, because I bethought myself that I could copy the function vecnorm from splus to my code. Then I was sad again because R complained >
2012 Oct 03
3
Fastest non-overlapping binning mean function out there?
Hi, I'm looking for a super-duper fast mean/sum binning implementation available in R, and before implementing z = binnedMeans(x y) in native code myself, does any one know of an existing function/package for this? I'm sure it already exists. So, given data (x,y) and B bins bx[1] < bx[2] < ... < bx[B] < bx[B+1], I'd like to calculate the binned means (or sums)
2009 Jul 20
3
S_alloc or Calloc for return value
I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the function is to do a sieving procedure, and the result will be small enough to fit into my
2001 Dec 14
2
colSums in C
Hi, all! My project today is to write a speedy colSums(), which is a function available in S-Plus to add the columns of a matrix. Here are 4 ways to do it, with the time it took (elapsed, best of 3 trials) in both R and S-Plus: m <- matrix(1, 400, 40000) x1 <- apply(m, 2, sum) ## R=16.55 S=52.39 x2 <- as.vector(rep(1,nrow(m)) %*% m) ## R= 2.39 S= 8.52 x3 <-