similar to: C Interface

Displaying 20 results from an estimated 9000 matches similar to: "C Interface"

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 =
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,
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;
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;
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
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 >
2007 Jun 06
3
C function with unknown output length
Hi all, Could anyone point me to one or more examples in the R sources of a C function that is called without knowing in advance what will be the length (say) of the output vector? To make myself clearer, we have a C function that computes probabilities until their sum gets "close enough" to 1. Hence, the number of probabilities is not known in advance. I would like to have an
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
2005 Sep 13
3
NUMERIC_POINTER question
Dear R-developers, Using .Call I pass a S4 class with e.g. the following class definition: setClass("mmatrix",representation( data="matrix") ) On the "C side" i do mat = GET_SLOT(vs,install("data")); and then: printf("%f\n",NUMERIC_POINTER(mat)[1]); The above print statement produces the correct output if xx<- new("mmatrix")
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
2012 May 03
1
Setting up a windows system for rcpp
I am running into a wall getting my system to work with rcpp and inline. Following Dirk's advice on stackoverflow, I hope someone is able to help me. My steps were to install MinGW 32 bit first, then installing Rtools, I disabled MinGW's entry in the PATH. I am trying to get the following code to work: library(Rcpp) library(inline) body <- ' NumericVector xx(x); return wrap(
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
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]),]
2009 May 26
1
passing "..." arguments to a function called by eval()
Hi everyone, I am starting learn to call C code from within R. So far, I've been trying toy problems to see if I can get them to work. One of the things I'd like to do is pass an arbitrary R function to C, evaluate the value in the C code using eval, and then return it. I also want to allow an arbitrary number of arguments to the function using "...". The code for my toy
2003 May 21
2
moving onto returning a data.frame?
I've been studying some of the code and I'm still a little shakey on the proper method for returning a data.frame from a C function (which is my ultimate goal here). I've started some code that I've "stolen" from the archives and I'm running into crashes, etc. I've been trying to gleen some insight from the src/main/scan.c file and didn't find many comments in
2006 Aug 21
1
return tree from .Call
Hello: I was hoping to get some advice about how to return a tree (basically a linked list -- with each node containing a parent, left, and right node pointers) from a C routine back into R. Each node itself contains several attributes (a double, a char *, an int, and a void * ) Initially I was thinking I could just return to R a SEXP containing a pointer to the Root Node, but then realized
1998 Jul 01
4
R-beta: R-0.62.1 under Digital Unix
I am grateful for the advice of Douglas Bates on my earlier problem in making R-0.62.1, but I'm afraid I'm still having problems.... I have been installing the various updates to R for quite some time on my alpha, and it is only now that I have been having really severe problems. The three or 4 versions before 0.61.1 installed without error. For 0.61.1 I needed to install GNU make. For
2004 Feb 26
1
Handling R Objects in C
Hello I want to handle R from a C/C++ project developped with Microsoft 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
2004 Jan 09
1
Call and memory
I use a large real matrix, X, in C code that is passed from R and transposed in place in the C code. I would like to conserve memory and, if possible, allocate space for only one copy of X -- hence I would like to pass a pointer to the data in the X object to the C code. The Writing R Extensions manual says that neither .Call nor .External copy their arguments. They also say that these
2007 Aug 03
2
Problem with making dll under Windows
Dear all, I have problems to compile a DLL for Windows XP with R version 2.5.1 (2007-06-27). See output below: C:\AZ_DATEN\C, C++\BE_speedup>R CMD SHLIB dmypow.c Goto undefined subroutine &DynaLoader::bootstrap_inherit at C:\Programme\R\R-2.5 .1\share\perl/XSLoader.pm line 80. Compilation failed in require at c:/Programme/Perl/lib/IO/Handle.pm line 262. BEGIN failed--compilation aborted