Displaying 20 results from an estimated 240 matches for "allocvector".
2006 Nov 17
1
Manipulating R lists in C
...I don't really need
to do as well in terms of creating extra string objects etc are also
helpful.
Many thanks
Tom
======EXTRACT=========
SEXP typeStr, volumeStr, priceStr, typeValStr;
SEXP priceList;
// create main list of vectors (unspecific items )
PROTECT( priceList = allocVector( VECSXP, 3 ) );
// for each item create a label and attach value
PROTECT( typeValStr = allocVector( STRSXP, 1 ) );
SET_STRING_ELT( typeValStr, 0,
mkChar( getPriceDataTypeAsString( p.getData().getType() ).c_str() ) );
SET_STRING_ELT( priceList, 0, typeValStr) ;
SEXP priceSXP;
P...
1998 Sep 22
1
"Segmentation Fault - core dumped" in R 0.62.3
I am occasional getting "Segmentation Fault - core dumped" in R 0.62.3 (I think
more often then I did in 0.62.2). I have not been able to do this in any
reliably reproducible way yet, but thought I would mention the problem in case
some else can isolate it.
Paul Gilbert
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read
2013 Apr 01
2
Timing of SET_VECTOR_ELT
Assume a C program invoked by .Call, that returns a list.
Near the top of the program we allocate space for all the list elements. (It is my habit
to use "xyz2" for the name of the R object and "xyz" for the pointer to its contents.)
PROTECT(means2 = allocVector(REALSXP, nvar));
means = REAL(means2);
PROTECT(u2 = allocVector(REALSXP, nvar));
u = REAL(u2);
PROTECT(loglik2 = allocVector(REALSXP, 2));
loglik = REAL(loglik2);
PROTECT(rlist = mknamed(VECSXP, outnames));
Can I assign the individual elements into rlist using SET_VE...
2003 Sep 05
1
Problem with S4 slots in C code (PR#4073)
...stdcall Test(void)
{
SEXP FLQuant, v,
d1, d2, d3, d4, d5,
dim, dimnames, names;
//Create new S4 object
PROTECT(FLQuant = NEW_OBJECT(MAKE_CLASS("FLQuant")));
//Create array for slot
//Set dimensions of array
PROTECT(dim = allocVector(INTSXP, 5));
INTEGER(dim)[0] = 1;
INTEGER(dim)[1] = 1;
INTEGER(dim)[2] = 1;
INTEGER(dim)[3] = 1;
INTEGER(dim)[4] = 1;
//Allocate memory
PROTECT(v = Rf_allocArray(REALSXP, dim));
//Create dimension names
PROTECT(dimnames = allocVector(VECS...
2014 Jun 26
1
using 2D array of SEXP for creating dataframe
.... So I wrote
the following code
SEXP dfm ,head,df , dfint , dfStr,lsnm;
*SEXP valueVector[2];*
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i,j;
//=============================
PROTECT(df = allocVector(VECSXP,2));
*PROTECT(valueVector[0] = allocVector(REALSXP,3));*
*PROTECT(valueVector[1] = allocVector(VECSXP,3));*
PROTECT(lsnm = allocVector(STRSXP,2));
SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
SEXP rawvec,headr;
unsigned char str[24]=&...
2014 Jun 24
2
using C code to create data frame but always return as list
...(jl_main_module, jl_symbol(dfname), (jl_value_t*)Var);
//Get Frame cols
sprintf(evalcmd,"size(%s,2)",dfname);
jl_value_t* cols=jl_eval_string(evalcmd);
int collen=jl_unbox_long(cols);
jl_value_t* eachcolvector;
//Create VECSXP
//Create SEXP for Each Column and assign
PROTECT(ans=allocVector(VECSXP,collen));
for (i=0;i<collen;i++)
{
sprintf(evalcmd,"%s[%d]",dfname,i+1);
eachcolvector=jl_eval_string(evalcmd);
SET_VECTOR_ELT(ans,i,Julia_R_MD_NA(eachcolvector));
}
//set names attribute
sprintf(evalcmd,"names(%s)",dfname);
jl_value_t* ret=jl_eval_string(e...
2014 Mar 06
1
Create dataframe in C from table and return to R
...------------------------------------------
My simple implementation is like this
SEXP formDF() {
SEXP dfm ,df , dfint , dfStr,lsnm;
char *ab[3] = {"aa","vv","gy"};
int sn[3] ={99,89,12};
char *listnames[2] = {"int","string"};
int i;
PROTECT(df = allocVector(VECSXP,2));
PROTECT(dfint = allocVector(INTSXP,3));
PROTECT(dfStr = allocVector(STRSXP,3));
PROTECT(lsnm = allocVector(STRSXP,2));
SET_STRING_ELT(lsnm,0,mkChar("int"));
SET_STRING_ELT(lsnm,1,mkChar("string"));
for ( i = 0 ; i < 3; i++ ) {
SET_STRING_ELT(dfStr,i,mkChar(ab[i]...
2013 Jul 13
2
missing PROTECT() in src/main/arithmetic.c
at lines 651 & 653 (integer_binary function):
if (code == DIVOP || code == POWOP)
ans = allocVector(REALSXP, n);
else
ans = allocVector(INTSXP, n);
There are calls to warningcall() later in the function, which can
trigger garbbage collection.
Looks like the typical scenario where it seemed pretty safe to not
PROTECT in the original version of the function but became very
unsafe 3...
2004 Jun 16
1
off topic: C/C++ codes for pseudo inverse
Hi,
I am looking for C/C++ codes for computing generalized
inverse of a matrix. Can anyone help me in this
regard?
Thanks,
Mahbub.
2007 Aug 23
1
.Call and to reclaim the memory by allocVector
...hing I
didn't read carefully in the R extension manual. My initial search on the
R help and R devel list archive didn't find useful information.
I am using .Call (as written in the R extension manual) for the C code
and have found that the .Call didn't release the memory claimed by
allocVector. Even after applying gc() function and removing the R object
created by the .Call function, the memory was still not reclaimed back to
the operating system.
Here is an example. It was modified from the convolve2 example from the R
extension manual. Now I am computing the crossproduct of a and b...
2007 Aug 23
1
.Call and to reclaim the memory by allocVector
...hing I
didn't read carefully in the R extension manual. My initial search on the
R help and R devel list archive didn't find useful information.
I am using .Call (as written in the R extension manual) for the C code
and have found that the .Call didn't release the memory claimed by
allocVector. Even after applying gc() function and removing the R object
created by the .Call function, the memory was still not reclaimed back to
the operating system.
Here is an example. It was modified from the convolve2 example from the R
extension manual. Now I am computing the crossproduct of a and b...
2005 Nov 07
3
R thread safe
...main kernel of the OpenMP
parallelization is a C SEXP function that performs the computational routine in
parallel with:
*******************
SEXP example(SEXP list, SEXP expr, SEXP rho)
{
R_len_t i, n = length(list);
SEXP ans, alocal;
omp_lock_t lck;
PROTECT(ans = allocVector(VECSXP, n));
ans = allocVector(VECSXP, n);
omp_init_lock(&lck);
#pragma omp parallel for default(none) private(i, alocal) shared(list,
lck,rho, ans, n, expr)
for(i = 0; i < n; i++) {
omp_set_lock(&lck);
PROTECT(alocal = allocVector(VECSXP, 1))...
2011 Jan 17
1
isoreg memory leak?
...EXP yc, yf, iKnots, ans;
const char *anms[] = {"y", "yc", "yf", "iKnots", ""};
/* unneeded: y = coerceVector(y, REALSXP); */
PROTECT(ans = mkNamed(VECSXP, anms));
SET_VECTOR_ELT(ans, 0, y = y);
SET_VECTOR_ELT(ans, 1, yc = allocVector(REALSXP, n+1));
SET_VECTOR_ELT(ans, 2, yf = allocVector(REALSXP, n));
SET_VECTOR_ELT(ans, 3, iKnots= allocVector(INTSXP, n));
... calculation ...
SETLENGTH(iKnots, n_ip);
UNPROTECT(1);
return(ans);
}
But if this is the problem, I am at a bit of a loss as to what SETLENG...
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
...t say "...another [protected] object..."?
Example from "5.7.4 Attributes" illustrating my question:
SEXP out(SEXP x, SEXP y)
{
R_len_t i, j, nx, ny;
double tmp;
SEXP ans, dim, dimnames;
nx = length(x); ny = length(y);
PROTECT(ans = allocVector(REALSXP, nx*ny));
for(i = 0; i < nx; i++) {
tmp = REAL(x)[i];
for(j = 0; j < ny; j++)
REAL(ans)[i + nx*j] = tmp * REAL(y)[j];
}
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny;
setAttrib(ans, R_...
2008 Apr 05
2
Adding a Matrix Exponentiation Operator
...*/
SEXP p1, p2, inv;
PROTECT(p1 = p2 = allocList(2));
SET_TYPEOF(p1, LANGSXP);
CAR(p2) = install("solve.default");
p2 = CDR(p2);
CAR(p2) = x;
inv = eval(p1, rho);
UNPROTECT(1);
return inv;
}
PROTECT(matrix = allocVector(mode, nrows * ncols));
PROTECT(tmp = allocVector(mode, nrows * ncols));
PROTECT(x_ = allocVector(mode, nrows * ncols));
PROTECT(x__ = allocVector(mode, nrows * ncols));
copyMatrixData(x, x_, nrows, ncols, mode);
// Initialize matrix to identity matrix
// Set x[i * ncols +...
2009 Mar 30
1
Setting the names attribute of a list?
...get
*** caught segfault ***
address 0x5, cause 'memory not mapped'
However, if i dont set the R_NamesSymbol, I do not get any such error.
Am I doing this correctly?
Thank you
Saptarshi
==CODE===
// kxp and usar are two SEXP's which have not been protected
SEXP res
PROTECT(res);
res= allocVector(VECSXP, 2);
SET_VECTOR_ELT(res,0,kxp);
SET_VECTOR_ELT(res,1,usar);
names=allocVector(VECSXP,2);PROTECT(names); //A
SET_VECTOR_ELT(names, 0, mkChar("key")); //A
SET_VECTOR_ELT(names, 1, mkChar("value")); //A
setAttrib(res, R_NamesSymbol,names); //A
UNPROTECT(2);
return(res);
S...
2007 Mar 14
1
allocVector reference
...opy y until x is modified, but for a
contiguous subset of y e.g. "x=y[5:9]" would become "x=vecref(y,5,5)".
SEXP vecref(SEXP v, SEXP offset, SEXP len)
{
// assuming v is an integer vector, offset>=0, len>=0 and
(offset+len)<length(v)
SEXP ans;
PROTECT(ans = allocVector(INTSXP, 0));
DATAPTR(ans) = INTEGER(v) + INTEGER(offset)[0]; // this
line doesn't work since DATAPTR is really an offset by the header
LENGTH(ans) = INTEGER(len)[0];
UNPROTECT(1);
return(ans);
}
Thanks in advance,
Matthew
2001 Mar 28
1
Help: Using R from C
...uot;R.h"
#include "Rinternals.h"
int main(void)
{
int i;
char *greeting;
SEXP x;
greeting = (char *) Calloc(31, char);
sprintf(greeting, "\nCallRFromC: test 1\n");
printf(greeting);
printf("Here is a vector:\n");
/* allocate an R vector */
PROTECT(x = allocVector(REALSXP, 10));
for(i=0; i<10; i++) {
REAL(x)[i] = (double)i;
printf(" x[%2d] = %lf\n", REAL(x)[i]);
}
UNPROTECT(1);
return 0;
}
The code builds without any problem (I am linking it with the import library
R.lib, and R.dll is in the path). While running, though, the code seg...
2018 Feb 02
1
R-gui sessions end when executing C-code
...double *psi_c; psi_c = REAL(psi);
/* Initialize new vectors not given as input */
SEXP q_copy = PROTECT(duplicate(q)); n_prot++;
double *q_c; q_c = REAL(q_copy);
SEXP q_new = PROTECT(allocVector(REALSXP,length(q))); n_prot++;
double *q_new_c; q_new_c = REAL(q_new);
SEXP eta = PROTECT(allocVector(REALSXP,H_c)); n_prot++;
double *eta_c; eta_c = REAL(eta);
SEXP exp_eta = PROTECT(alloc...
2005 Mar 10
1
R_alloc with more than 2GB (PR#7721)
...lloc, see
below. Would it be possible to have allocString take a long argument as well?
These code excerpts are from R-devel_2005-03-10.tar.gz:
char *R_alloc(long nelem, int eltsize) {
R_size_t size = nelem * eltsize;
SEXP s = allocString(size);
...
}
SEXP allocString(int length) {
return allocVector(CHARSXP, length);
}
SEXP allocVector(SEXPTYPE type, R_len_t length) {
...
case CHARSXP:
size = BYTE2VEC(length + 1);
...
malloc(sizeof(SEXPREC_ALIGN) + size * sizeof(VECREC)))
...
}