Displaying 20 results from an estimated 200 matches similar to: "C++: Appending Values onto an R-Vector."
2003 Dec 10
0
C++: SET_LENGTH() Over Many Iterations?
In a C++ extension to R (v 1.8.1), I've been experimenting with a
generic "push back" function to tack one value at a time onto the end
of an R vector created within the extension. After calling this
function a certain number of times Rgui.exe (I'm writing in Windows
using Visual Studio .NET 2003) will fail with an Access Violation,
which doesn't happen when I pre-allocate
2005 Aug 29
1
Question about SET_LENGTH
Hello all, thanks for all the help on the other issues. This one should
be relatively straightforward. I have a vector of integers which I
allocate to be the maximal size possible (meaning I'll never see more
than cel.GetNumOutliers, but most likely I'll see less) therefore, I
want to resize the vector, one solution would be to allocate a new
vector then to copy into the new vector. That
2000 Apr 01
1
Bug ? mine or ? in R core
Dear R Gurus,
I would very much appreciate some help with this code snippit
from my RODBC package.
R crashes or exhibits bizarre behaviour when repeatedly fetching
large numbers of rows.
Examples:
> odbcFetchRows(0,max=50000)->xx
> odbcFetchRows(0,max=50000)->xx
> odbcFetchRows(0,max=50000)->xx
> odbcFetchRows(0,max=50000)->xx
> odbcFetchRows(0,max=50000)->xx
3rd
2005 Apr 16
1
SET_LENGTH
Hello.
I'm trying to read a delimited file. I'm a little new
to the R api. In the program, I do something like
this...
/*****************************/
SEXP retval;
PROTECT(retval = allocMatrix(STRSXP,1,names.dim));
int r_eltctr = 0;
while(!myfile.eof())
{
SET_LENGTH(retval,r_eltctr+num_of_fields);
for(int i = 0;numofcolumns; ++i)
{
INTEGER(retval)[r_eltctr++] = 1;/*some
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
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;
2005 Apr 14
1
question about "R get vector from C"
Dear ALL-R helpers,
I want to let R get vector from c ,for 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
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
2004 Jun 22
3
[Q] GET_DIM() crash on Windows only
I have the following contrived code in package format.
On Solaris and Mac OS X, code runs just fine. On Windows,
it crashes the R environment with the "Send Bug Report"
dialog. I tried R 1.8.1 (Win2K) and R 1.9 (WinXP) binaries
with the same result. PCs otherwise appear properly
configured for creating R packages. Anything blatantly
wrong? Suggestions?
TIA
Relevant files from package
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")
2019 Jun 14
2
R C API resize matrix
Hi,
Is there a way to resize a matrix defined as follows:
SEXP a = PROTECT(allocMatrix(INTSXP, 10, 2));
int *pa = INTEGER(a)
To row = 5 and col = 1 or do I have to allocate a second matrix "b" with
pointer *pb and do a "for" loop to transfer the value of a to b?
Thank you
Best regards
Morgan
[[alternative HTML version deleted]]
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
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
2006 May 08
1
Calling C++ code fom R --How to export C++ "unsigned" integer to R?
Hello all,
Is there a way to export C++ "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;
2005 Apr 03
2
Error: cannot set length of non-vector
The subject line says it all. How can I find what
Error: cannot set length of non-vector
means? RTFS is no help. I can find out of course that
it comes from "lengthgets", but who called that? Not me!
The situation is as follows. I am trying to get a package
ready for CRAN. Every time I run "R CMD check" I get this
error when building the package vignette. But (!)
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
2019 Jun 17
0
R C API resize matrix
Matrix is just a vector with the dim attribute. Assuming it is not referenced by anyone, you can set any values to the dim attribute. As for the vector, you can use SET_LENGTH() to shorten it - but I'm not sure how official it is - it was originally designed to work, but there were abuses of TRUELENGTH so not sure where we stand now (shortened vectors used to fool the garbage collector as far
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
2010 Mar 11
1
Shrinking a List
Hello,
I create a VECSXP(call it A) with size N(~ 5000), i then proceed to
fill the elements and find out I don't need to fill more than
M (M<< N).
Thus if i return A to the user's R code, he/she will see a list of
length 5K of which N-M are NULLs.
To avoid this, I create a new VECSXP B of length M and /duplicate/ the
elements of A.
Since I do this often, it appears to be wasteful,
2005 Feb 24
2
mutable Query objects
There's a bit of an API glitch with Query objects at present. This code
shows it off:
Xapian::Database("/path/to/db");
Xapian::Enquire enquire(db);
// make a simple query
Xapian::Query myquery(Xapian::Query::OP_NEAR, phrase, phrase + 2);
enquire.set_query(myquery);
// Now change the query - this shouldn't affect the query enquire
// will run, but it does.