similar to: Handling R Objects in C

Displaying 20 results from an estimated 1000 matches similar to: "Handling R Objects in C"

2004 Jun 16
1
Compiling C++ package source: linking problem?
Dear All I'm currently developing a package for R (1.9.0) on Win32, with C++ source code. Having followed the instructions in readme.packages, my code compiles fine with R CMD SHLIB (as well as R CMD check) ... until I start using the internal R functions. (Interesting: Rprintf seems to be the exception.) For instance, the following code compiles fine: #include <R.h> #include
2010 Jun 18
3
C interface
Greetings, I am trying to call 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 =
2010 Jun 15
1
Error when callin g C-Code
Hi when I call the function below in R, i get the error: Object 'pairlist' can't be converted to 'double'. #include <R.h> #include <Rdefines.h> #include <Rmath.h> SEXP CSimPoisson(SEXP lambda, SEXP tgrid, SEXP T2M, SEXP Ni, SEXP NT) { double sign, EVar; double *xlambda, *xtgrid, *xT2M, *xNi, *xNT, *xtau; SEXP tau; int ltgrid =0; int i = 0; int j = 0;
2010 Jun 18
4
C Interface
Greetings, I am trying to call 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 =
2009 Apr 09
1
.Call()
Hi guys, I want to transfer the following code from R into .Call compatible form. How can i do that? Thanks!!! INT sim; for(i in 1:sim){ if(i>2) genemat <- genemat[,sample(1:ncol(genemat))] ranklist[,1] <- apply(genemat, 1, function(x){ (mean(x[cols]) - mean(x[-cols]))/sd(x)}) ranklist <- ranklist[order(ranklist[,1]),]
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
I'm continuing my work on finding speedups in generalized inverse calculations in some simulations. It leads me back to .C and .Call, and some questions I've never been able to answer for myself. It may be I can push some calculations to LAPACK in or C BLAS, that's why I realized again I don't understand the call by reference or value semantics of .Call Why aren't users of
2004 Jun 30
1
AS_NUMERIC and as.numeric - Could someone explain?
Dear List, I stepped into a strange effect which I can't explain to myself (probably due to lack of knowledge on R internals). I have four vectors a,b,c and z of size 10000 each. With these vectors I call .Call("hyp2f1forrey", a, b, b, z, PACKAGE = "hyp2f1") to access SEXP hyp2f1forrey(SEXP a, SEXP b, SEXP c, SEXP x) { int i,n; double *xa, *xb, *xc, *xx,
2013 May 24
1
Problem with Rboolean in c++ code
I am trying to use R_RegisterCFinalizerEx to ensure some c++ object is properly deleted after use. However, I run into some problems when trying to pass in the third argument which is an Rboolean. The line 'R_RegisterCFinalizerEx(p, finalizer, TRUE);' generates the following error when trying to compile using R CMD SHLIB: g++ -I/usr/share/R/include -DNDEBUG -fpic -O2 -pipe
2005 Dec 21
1
linking C and R
hey, I am running R 2.0.1 on a the terminal of my MAC OS X and I have written some C code that I would like to use dynload to bring into R. When I try to compile the code i get the error R.defines.h no such file or directory. I know that the file is in resources/include but where do I have to move the file to so that the compiler can access it? I tried copying Rdefines.h and R_ext folders
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;
2000 May 15
1
pythag missing in src/appl/ROUTINES (PR#544)
Full_Name: Roger Bivand Version: 1.0.1 OS: Linux RH 6.1 Submission from: (NULL) (158.37.102.52) I am trying to use pythag() from src/appl in a .Call() function. pythag seems to be missing from the ROUTINES list in appl - putting it in solved the problem: > x <- 1 > y <- 1 > sqrt(x^2 + y^2) [1] 1.414214 > dyn.load("pythagtry.so") Error in dyn.load(x,
2007 Apr 11
1
Programming Problem (for loop, random # control, 3 dimentional graph)
Dear List, This is just a programming problem which i cannot seem to figure out. I am trying to get a set of power from a test (say, kolmogorov smirnov) out of a distribution (say, G-K distribution) as follows. I am trying to reduce to pain of writing the whole set of data points (p# below) using "for" loop. However, I seem to have some problem in it as the output "M" does not
2008 Mar 15
1
Experimental R_has_slot() utility
Dear list, The utility "R_has_slot" mentioned in the file NEWS ("Experimental R_has_slot() utility supplementing R_do_slot()") appears to be missing from a fresh checkout of the development branch. $ svn up At revision 44759. $ grep -i has_slot `find include -name '*.h'` $ grep -i _slot `find include -name '*.h'` include/Rdefines.h:#define GET_SLOT(x, what)
1999 Oct 27
1
Rdefines.h
Hi all, may I request the following two changes to Rdefines.h (R 0.65.1)? 1.) Change line 106 from #define Free(p) R_chk_free( (void *)(p) ) to #define Free(p) R_chk_free( (void *)(p) ) , p=NULL 2.) Add after line 79: #define PROBLEM {char R_problem_buf[R_PROBLEM_BUFSIZE];sprintf(R_problem_buf, a new line 80: #define PROBLEM {char
2007 Apr 03
3
Strange number produced by dnorm
Hi All, I just started to learn compiling C codes for R usage, and got a problem when I was playing with my 'hello world' code. #include <R.h> #include <Rdefines.h> #include <Rmath.h> SEXP test( ) { double x; x=dnorm(1.0,0.0,1.0,1); printf(" x value is: %d \n",x); return(R_NilValue); } I got the result : x value is: -466460838 Could
2008 Apr 18
1
R-extension in unix system -- help to locate header files
Hi list, To call C, I used to use R-extension in windows but I'm moving to unix system because my PC doesn't have enough memory. My C codes requires to include the following header files: #include <stdlib.h> #include <R.h> #include <Rdefines.h> #include <Rmath.h> #include <R_ext/Applic.h> #include <R_ext/PrtUtil.h> In windows, I had no problem with it
2005 Aug 20
1
Implementing a single-precision class with raw
A package that I develop (xcms) sometimes needs to read and process vectors several hundreds of megabytes in size. (They only represent parts of a large data sets which can approach nearly 100GB.) Unfortunately, R sometimes hits the 2GB memory limit of Win32. To help cut the memory footprint in half, I'm implementing a "float" class as a subclass of "raw". Because
2014 Sep 07
1
lbfgsb from C/C++
Hi, I would like to call R's lbfgsb function 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
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 >
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