Displaying 19 results from an estimated 19 matches for "new_integ".
Did you mean:
new_integer
2013 Jun 27
3
Read a text file into R with .Call()
Hi,
I want to read a text file into R with .Call().
So I define some NEW_CHARACTER() to store the chracters read and use SET_STRING_ELT to fill the elements.
e.g.
PROTECT(qNames = NEW_CHARACTER(10000));
char *foo; // This foo holds the string I want.
while(foo = readLine(FN)){
SET_STRING_ELT(qNames, i, mkChar(foo)));
}
In this way, I can get the desired character from qNames. The only problem
2003 Dec 12
3
C++: Appending Values onto an R-Vector.
...onto the end of a vector.
However, when I use this function to push back a large number of
values one at a time, Rgui.exe (I'm working with R 1.8.1 in Windows
XP) crashes from an Access Violation; if, however, I pre-allocate
space (is the space actually pre-allocated?) for the vector (say with
NEW_INTEGER(n) rather than NEW_INTEGER(0)) and insert values into the
allocated slots, the code works fine. If you'd like to see some test
code, I've already posted it here:
https://www.stat.math.ethz.ch/pipermail/r-help/2003-December/041871.html
Here's my question, then: Is SET_LENGTH() the ap...
2001 Sep 10
1
not safe to return vector pointer
Hello All,
I recently upgraded from R-1.1.1 to R-1.2.2.
I have an R function that uses .Call() to
return a list from C code. The C code
has the form:
SEXP function(SEXP var)
{
SEXP rlist ;
PROTECT(rlist = NEW_LIST(3)) ;
VECTOR_PTR(rlist)[0] = NEW_INTEGER(1) ;
VECTOR_PTR(rlist)[1] = NEW_STRING(1) ;
...
UNPROTECT(1) ;
return(rlist) ;
}
When I try to .Call("function",...) from R I get
the following error message:
Error: not safe to return vector pointer
Why is it no longer safe to return a vector pointer?
How can I correc...
2006 May 08
1
Calling C++ code fom R --How to export C++ "unsigned" integer to R?
...;unsigned" integer to R? (I am trying to parse
files in "BPMAP" format, and some variables are of type unsigned int (first
declared in C++) ).
I know that to export signed integer to R,
I can do the following in C++:
int Some_INTEGER = 5;
int *p_myInt;
SEXP myInt;
PROTECT(myInt=NEW_INTEGER(1));
myInt[0] = Some_INTEGER;
UNPROTECT(1);
return myInt;
However, it appears that myInt is a signed integer.
I have looked over Rdefines.h and it does not look like there is a
definition for NEW_UNSIGNED_INTEGER !
How would I export an unsigned integer to R?
obviously this won't wo...
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);
If I uncomment the lines 5 to 8 than all is working fine four small count's (tested 10,20).
But if the result is an array with about 2000 entries R crashes vicious an...
2000 Apr 01
1
Bug ? mine or ? in R core
...ansposing, not used here*/
long maximum=(long)REAL(max)[0];
long j=1,k=1, /* row counters*/
buffsize=(long)REAL(bs)[0], /* prealloc if row count NA*/
length,offset,t_offset; /* counts into output buf*/
NCOLS=1;
PROTECT(ans=NEW_LIST(2)); /*create answer [0] = data, [1]=stat */
PROTECT(stat=NEW_INTEGER(1)); /* numeric status vector */
PROTECT(data=NEW_CHARACTER(buffsize));
while(1){
for (i=1; i<= NCOLS; i++){
offset=((i-1)*maximum)+(j-1);
}
DBG(2,"writing to data");
STRING(data)[offset]=COPY_TO_USER_STRING("Some dummy data");
if(offset +NCOLS >= buffsize)...
2003 Dec 10
0
C++: SET_LENGTH() Over Many Iterations?
...shBackTest(SEXP args)
{
SEXP arg1, arg2, int_vect;
PROTECT(arg1 = AS_INTEGER(CADR(args)));
int n_reps = INTEGER_POINTER(arg1)[0];
PROTECT(arg2 = AS_LOGICAL(CADDR(args)));
bool full_alloc = (LOGICAL_POINTER(arg2)[0] ? true : false);
if (full_alloc)
PROTECT(int_vect = NEW_INTEGER(n_reps));
else
PROTECT(int_vect = NEW_INTEGER(0));
for (int i = 0; i < n_reps; ++i) {
Rprintf(" ** Iteration %d:\n", i + 1);
if (full_alloc)
INTEGER_POINTER(int_vect)[i] = i;
else
PUSH_BACK_INTEGER(int_vect, i);
}
SEXP out, n...
2005 Apr 14
1
question about "R get vector from C"
...example :numeric array ,vector .I saw
some exmple like this :
/* useCall3.c */
/* Getting an integer vector from C using .Call */
#include <R.h>
#include <Rdefines.h>
SEXP setInt() {
SEXP myint;
int *p_myint;
int len = 5;
PROTECT(myint = NEW_INTEGER(len)); // Allocating storage space
p_myint = INTEGER_POINTER(myint);
p_myint[0] = 7;
UNPROTECT(1);
return myint;
}
then type at the command prompt:
R CMD SHLIB useCall3.c
to get useCall3.so
In windows platform ,how can I create right dll to let dyn.load use
and for .c ,.call ,extern...
2005 Aug 29
1
Question about SET_LENGTH
...to allocate a new
vector then to copy into the new vector. That is what I was going to do
until I saw the SET_LENGTH macro. Does this macro effectively take care
of the memory? Is this an acceptable use of the macro? The code works,
but I dont want any lurking memory problems.
PROTECT(outliers = NEW_INTEGER(cel.GetNumOutliers()));
if (i_readOutliers != 0) {
if (noutlier == 0) {
outliers = R_NilValue;
}
else if (noutlier < cel.GetNumOutliers()) {
SET_LENGTH(outliers, noutlier);
}
}
Thanks as always!
jim
2008 Mar 05
1
SEXP size management.
Hi,
Trying to decrease the size of a SEXP variable without reassigning
values individually in a loop.
So far, I've tried using Realloc, as the follow source demonstrates:
SEXP dothis() {
SEXP Rblah;
PROTECT(Rblah = NEW_INTEGER(6));
int* blah = INTEGER(Rblah);
blah[0] = 1;
blah[1] = 2;
blah[2] = 3;
Realloc(Rblah, 3, INTEGER);
UNPROTECT(1);
return(Rblah);
}
According to the documentation, I think that this should work, however
it returns an error on compile: "test.c:17: error: expected expression
before &...
2004 Jan 09
1
Call and memory
...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;
SET_ELEMENT(alist,2,rvector);
UNPROTECT(1);
PROTECT(kvector=NEW_INTEGER(1));
INTEGER_POINTER(kvector)[0]=k;
SET_ELEMENT(alist,3,kvector);
UN...
2006 Aug 21
1
return tree from .Call
...t = 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_VECTOR_ELT( node, 0, tree_double) ;
SET_VECTOR_ELT( node, 1, tree_char) ;
SET_VECTOR_ELT( node, 2, tree_int) ;...
2003 Dec 09
1
R Interface handholding
...king on generating R interfaces.
For starters, I've written the following R function (which compiles):
SEXP myincr(SEXP Rinput)
{ // Returns input integer incremented by one
int input;
SEXP returner;
PROTECT(Rinput = AS_NUMERIC(Rinput));
input = * INTEGER(Rinput);
input++;
PROTECT(returner = NEW_INTEGER(input));
Rprintf("Hey there\n");
return returner;
}
I've made this into a package, by dropping it into a stub directory
along with something called init.c:
#include "areone.h"
#include <R_ext/Rdynload.h>
#include <Rinternals.h>
R_NativePrimitiveArgType myinc...
2004 Jun 22
3
[Q] GET_DIM() crash on Windows only
...;
#endif
if (GetMatrixDimen(vntX, &m, &n) != 2)
{
error("'x' is not a two dimensional matrix");
/*NOTREACHED*/
}
#ifdef DEBUG_GETDIM
REprintf("\tm = %d\n", m);
REprintf("\tn = %d\n", n);
#endif
PROTECT(vntOut = NEW_INTEGER(2));
INTEGER(vntOut)[0] = m;
INTEGER(vntOut)[1] = n;
UNPROTECT(1);
return vntOut;
}
tests/getdim.R
--------------
library(getdim)
test.getdim <- function(input, expected) {
result <- getdim(input);
identical(all.equal(result, expected), TRUE);
}
mat <- matrix...
2003 Jun 23
3
FW: S4 classes, creating in C
...;
SEXP adims, pivot, val;
int m, n, info;
if (!isMatrix(aa) || !isReal(aa)) {
error("A must be a double precision matrix");
}
adims = GET_DIM(aa); m = INTEGER(adims)[0]; n = INTEGER(adims)[1];
pivot = PROTECT(NEW_INTEGER(m < n ? m : n));
F77_CALL(dgetrf)(&m, &n, REAL(aa), &m, INTEGER(pivot), &info);
check_Lapack_error(info, "dtrtrf");
val = PROTECT(NEW_OBJECT(MAKE_CLASS("LUdecomposition")));
SET_SLOT(val, install("a"...
2005 Jul 12
1
allocation of large matrix failing
.../GC issue, but I submit it
may be.
<code>
int numHits = seq.GetNumberHits();
Rprintf("numHits:%d\n", numHits);
Rprintf("before allocation...\n");
SEXP oligos, matrix;
PROTECT(oligos = NEW_LIST(numHits));
Rprintf("allocated oligo list...\n");
PROTECT(matrix = NEW_INTEGER(numHits*8));
Rprintf("entering looop...\n");
<output>
entering sequence loop.
numHits:333559
before allocation...
allocated oligo list...
It hangs here everytime (never printing "entering loop..." - i have
waited like 10 minutes). If I remove the 8 then it completes....
2005 Jul 26
1
Error registering finalizer
...= MAKE_CLASS(PROBESET_GE_CLASS_NAME)); n++;
PROTECT(vntObj = NEW_OBJECT(vntClassDef)); n++;
PROTECT(vntHandle = AllocateProbesetGEPtr(count)); n++;
SET_SLOT(vntObj, HandleSlotSymbol, vntHandle);
PROTECT(vntData = R_ExternalPtrProtected(vntHandle)); n++;
PROTECT(vntAttr = NEW_INTEGER(1)); n++;
INTEGER(vntAttr)[0] = count;
SET_COUNT(vntData, vntAttr);
>>>>> Problem comes here <<<<<<
R_RegisterCFinalizer(vntData, (R_CFinalizer_t)ProbesetGE_finalizer);
UNPROTECT(n);
return vntObj;
}
Thanks for any pointers...
-----------...
2009 Sep 16
2
I want to get a reference to this time series object
I'm trying to get a reference to this object in C
SWX.RET[1:6,c("SBI,"SPI","SII")]
While i am able to access and use a plain SWX.RET object, I'm getting
confused on how to create an object with the array subscripts like above.
Here is what I tried to do. It doesn't work because "[" is obviously not an
operation or function on SWX.RET. So how do I
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