Displaying 9 results from an estimated 9 matches for "set_length".
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
value...*/
}
++r_eltctr;
}
UNPROTECT(1);
/***************************************/
There is a segmentation fault when SET_LENGTH() is
called several iterations into the progr...
2005 Aug 29
1
Question about SET_LENGTH
...locate 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 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_NilVa...
2003 Dec 10
0
C++: SET_LENGTH() Over Many Iterations?
...to the reserved slots; i.e., I'm not trying to create an R object too
big to be handled by R within the context of my OS's available memory.
Here's some simple test code I've been running:
<CPP Code>
#define PUSH_BACK_INTEGER(v, x) \
do {\
UNPROTECT_PTR(v);\
SET_LENGTH(v, GET_LENGTH(v) + 1);\
PROTECT(v);\
INTEGER_POINTER(v)[GET_LENGTH(v) - 1] = x;\
}\
while (false)
SEXP R_SimplePushBackTest(SEXP args)
{
SEXP arg1, arg2, int_vect;
PROTECT(arg1 = AS_INTEGER(CADR(args)));
int n_reps = INTEGER_POINTER(arg1)[0];
PROTECT(arg2 =...
2003 Dec 12
3
C++: Appending Values onto an R-Vector.
Hi folks. I posted this question a few days ago, but maybe it got lost
because of the code I included with it. I'm having a problem using the
SET_LENGTH() macro in an R extension I'm writing in C++. In a function
within the extension I use SET_LENGTH() to resize R vectors so as to
allow the concatenation of single values onto the vectors -- it's a
"push back" function to append values onto the end of a vector.
However, when I use...
2000 Apr 01
1
Bug ? mine or ? in R core
...;= 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){
DBG(1,"reallocating space");
length=length(data);
buffsize=length+buffsize;
SET_LENGTH(data,buffsize);
}
j++;
if(maximum && j>maximum)
break;
}
/* transpose it */
DBG(1,"trimming");
SET_LENGTH(data,j*NCOLS); /* trim down buffer*/
INTEGER(stat)[0]=status;
PROTECT(dim=NEW_INTEGER(2));
INTEGER(dim)[1]=NCOLS;
INTEGER(dim)[0]=length(data)/NCOLS;
DBG(2,&qu...
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]]
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
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 as object sizes go). I wouldn't do it unless you're dealing with ra...
2005 Feb 24
2
mutable Query objects
...it in
Enquire::set_query()
(b) make Query object immutable by replacing these non-const public
methods with extra constructor parameters:
void set_window(Xapian::termpos window);
void set_cutoff(Xapian::weight cutoff);
void set_elite_set_size(Xapian::termcount size);
Xapian::termcount set_length(Xapian::termcount qlen);
The private non-const methods are only used during construction, so
they're not a problem.
I tend to favour (b). The first three are tied to particular OPs
(OP_NEAR/OP_PHRASE, OP_WEIGHT_CUTOFF, and OP_ELITE_SET respectively)
so are perhaps cleaner that way anyway. T...