search for: set_vector_elt

Displaying 20 results from an estimated 94 matches for "set_vector_elt".

2004 Mar 17
1
best methods for strings and structures?
...precip_in_hg; }; with an internal function and I'm building the return object using the following code: PROTECT( ret_val = allocVector( VECSXP, 13 ) ); SET_STRING_ELT( ret_val, 0, mkChar( cfg_rec.coeffs_filename) ); SET_STRING_ELT( ret_val, 1, mkChar( cfg_rec.species_filename) ); SET_VECTOR_ELT( ret_val, 2, ScalarInteger( cfg_rec.use_random_error ) ); SET_VECTOR_ELT( ret_val, 3, ScalarInteger( cfg_rec.random_seed ) ); SET_VECTOR_ELT( ret_val, 4, ScalarInteger( cfg_rec.endemic_mortality ) ); SET_VECTOR_ELT( ret_val, 5, ScalarInteger( cfg_rec.sdi_mortality ) ); SET_VECTOR_ELT( r...
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
2013 Apr 01
2
Timing of SET_VECTOR_ELT
...Vector(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_VECTOR_ELT at this point, or do I need to wait until the end of the program, after I've filled in means[i], u[i], etc.? I likely depends on whether I'm assigning a pointer or a copy. Terry T.
2006 Aug 21
1
return tree from .Call
...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) ; SET_VECTOR_ELT( node, 3, tree_voidPTR ) ; SET_VECTOR_ELT( list, i, node ) ; } UNPROTECT( tree->size * 4 ) ; ??? Tricky.. return( list ) ; Look reasonable ? THANKS ! [[al...
2005 Mar 16
3
Write Barrier: was: function-like macros undefined
...o http://www.stat.uiowa.edu/~luke/R/barrier.html. I have a couple of questions in this regard: * suppose that inside a C function I have a SEXP vector x of integers and I want to increment each element by one. I understand that int * xIPtr = INTEGER(x); int i; for (i=0; i<LENGTH(x); ++i) SET_VECTOR_ELT(x, i, xIPtr[i]+1); is the recommended way of doing it. However it seems that only the very first call to SET_VECTOR_ELT, i.e. the one that corresponds to i=0, is strictly necessary. For example, and this is my question, the following should be perfectly safe: SET_VECTOR_ELT(x, 0, xIPtr[0]); for...
2006 Nov 17
1
Manipulating R lists in C
...locVector( STRSXP, 1 ) ); SET_STRING_ELT( typeValStr, 0, mkChar( getPriceDataTypeAsString( p.getData().getType() ).c_str() ) ); SET_STRING_ELT( priceList, 0, typeValStr) ; SEXP priceSXP; PROTECT( priceSXP = allocVector( REALSXP, 1) ); REAL(priceSXP)[0] = p.getData().getPrice(); SET_VECTOR_ELT( priceList, 1, priceSXP); SEXP volumeSXP; PROTECT( volumeSXP = allocVector( REALSXP, 1 ) ); REAL(volumeSXP)[0] = p.getData().getVolume(); SET_VECTOR_ELT( priceList, 2, volumeSXP); ********WORKS UP TO HERE************* // add the names of the list items (type,price,volume) SE...
2009 Mar 30
1
Setting the names attribute of a list?
...*** 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); Saptarshi Guha
2011 Jan 17
1
isoreg memory leak?
...= LENGTH(y), i, ip, known, n_ip; double tmp, slope; SEXP 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 th...
2012 Aug 08
2
RQuantLib: SET_VECTOR_ELT() can only be applied to a 'list', not a 'symbol'
...period="Quarterly", businessDayConvention = "Unadjusted", terminationDateConvention= "Unadjusted") coupon <- c(0.0465) CallableBond(bondparams, HullWhite, coupon, dateparams) # ...I get the following error: # ---> SET_VECTOR_ELT() can only be applied to a 'list', not a 'symbol' <--- # Wandering through Internet, I found something similar to my # issue which has been solved by updating packages. # I tried the same but no results :( # Two weeks ago the same code worked properly. # Any idea about what...
2003 Sep 05
1
Problem with S4 slots in C code (PR#4073)
...m)[2] = 1; INTEGER(dim)[3] = 1; INTEGER(dim)[4] = 1; //Allocate memory PROTECT(v = Rf_allocArray(REALSXP, dim)); //Create dimension names PROTECT(dimnames = allocVector(VECSXP, 5)); PROTECT(d1 = allocVector(INTSXP, 1)); INTEGER(d1)[0] = 1; SET_VECTOR_ELT(dimnames, 0, d1); PROTECT(d2 = allocVector(INTSXP, 1)); INTEGER(d2)[0] = 2000; SET_VECTOR_ELT(dimnames, 1, d2); PROTECT(d3 = allocVector(STRSXP, 1)); SET_STRING_ELT(d3, 0, mkChar("combined")); SET_VECTOR_ELT(dimnames, 2, d3); PROTECT(d4 = alloc...
2006 May 23
1
protect
...R (more specifically, I need to close various files). Would I then need to protect foo, as in SEXP bar; bar = foo(); "close the file in C++" return bar; Finally, I am also assigning values to the components of a list. Would the following be ok SEXP bar; PROTECT(bar = NEW_LIST(2)); SET_VECTOR_ELT(bar, 0, ScalarInteger(test()); (where test is a function returning int, which again has nothing to do with R - it interfaces to an extern library), or do I need to hedge myself against garbage collection in the SET_VECTOR_ELT macro? /Kasper
2013 Nov 05
1
Dynamic list creation (SEXP in C) returns error "unimplemented type (29) in 'duplicate'"
...s ("L1") elements (input list). The steps I've follow are: FIRST: Create the "mother list" of size "n=length(L0)" (doesn't change) and protect it as PROTECT(L1=allocVector(VECEXP, length(L0))) and filling it with vectors of length two: for(i=0;i<n;i++) SET_VECTOR_ELT(L1,i, allocVector(VECSXP, 2)); then, for each element of the mother list: for(i=0;i<n;i++) { SECOND: By reading this post in Stackoverflow http://stackoverflow.com/questions/7458364/growing-an-r-matrix-inside-a-c-loop/7458516#7458516 I understood that it was necesary to (1) create the &quot...
2009 Sep 20
1
Return a list from a .Call but segfaults
...SEXP k = R_NilValue; PROTECT(KV = Rf_allocVector(VECSXP, 2)); r = reverseUInt(*((int*) rawdata)); //converts network order to host rawdata+=4; //yes, hard code size of int PROTECT(k= kk_(rawdata,r)); //deserializes data and returns a SEXP rawdata+= r; SET_VECTOR_ELT(KV,0, k); UNPROTECT(1); r = reverseUInt(*((int*) rawdata)); rawdata+=4; PROTECT(k= kk_(rawdata,r)); rawdata+=r; SET_VECTOR_ELT(KV,1, k); UNPROTECT(1); SET_VECTOR_ELT(rval,i,KV); UNPROTECT(1); } UNPROTECT(1); return(rval...
2015 Sep 26
1
grDevice in R HEAD been broken for 6 weeks.
...---------------------------------------- It seems to be broken by the GE_SaveSnapshotState addition in src/library/grid/src/state.c: case GE_SaveSnapshotState: + /* + * Save the current 'grid' DL. + */ + PROTECT(result = allocVector(VECSXP, 3)); + SET_VECTOR_ELT(result, 0, gridStateElement(dd, GSS_DL)); + SET_VECTOR_ELT(result, 1, gridStateElement(dd, GSS_DLINDEX)); + UNPROTECT(1); break; > showCols2() Loading required package: grid Error in grDevices:::recordPalette() : LOGICAL() can only be applied to a 'logical', not...
2010 Mar 07
1
duplicate STRSXP : shallow copy ?
...; SEXP y = PROTECT( duplicate( x ) ); int n = LENGTH(x); int nc = 0 ; char* p = 0 ; for( int i=0; i<n; i++){ p = (char*)( CHAR( STRING_ELT( y , i ) ) ); nc = strlen( p ) ; for( int j=0; j<nc; j++){ p[j] = tolower( p[j] ) ; } } SEXP res = PROTECT( allocVector( VECSXP, 2 ) ); SET_VECTOR_ELT( res, 0, x ); SET_VECTOR_ELT( res, 1, y ); UNPROTECT(2) ; return res ; ', includes = "#include <ctype.h>" ) I get : > fx( c("Tick", "Tack", "Tock" ) ) [[1]] [1] "tick" "tack" "tock" [[2]] [1] "tick"...
2014 Mar 06
1
Create dataframe in C from table and return to R
...cVector(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])); INTEGER(dfint)[i] = sn[i]; } SET_VECTOR_ELT(df,0,dfint); SET_VECTOR_ELT(df,1,dfStr); setAttrib(df,R_NamesSymbol,lsnm); //PROTECT(dfm=LCONS(dfm,list3(dfm,R_MissingArg,mkFalse()))); UNPROTECT(4); dfm = PROTECT(lang2(install("data.frame"),df)); SEXP res = PROTECT(eval(dfm,R_GlobalEnv)); UNPROTECT(2) } ----------------------------...
2000 Aug 09
2
GenGC changes
...ects) are handled differently from the numerical atomic types. >From ``Writing R Extensions'': Earlier code was written in a style like. VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol); but that is no longer allowed. The functions `VECTOR_ELT' and `SET_VECTOR_ELT' must now be used to access and set elements of a generic vector. There are analogous functions `STRING_ELT' and `SET_STRING_ELT' for character vectors. To convert existing code, use the following replacements. original replacement...
2009 Jul 03
2
Error using the Rdonlp2‏ Package
...4e+08 upsi= 0.0e+00 b2n= 5.0e+08 umi= 0.0e+00 nr 0 si-1 2 fx= -2.111002e+09 upsi= 0.0e+00 b2n= 5.1e+08 umi= 0.0e+00 nr 14 si-1 3 fx= -5.961701e+09 upsi= 0.0e+00 b2n= 4.1e+08 umi= 0.0e+00 nr 16 si-1 *Error Message:* Error in tryCatchList(expr, classes, parentenv, handlers) : SET_VECTOR_ELT() can only be applied to a 'list', not a 'character' [[alternative HTML version deleted]]
2008 Jan 04
1
Evaluating R expressions from C
...(list)) error("`list' must be a list"); if(!isEnvironment(rho)) error("`rho' should be an environment"); PROTECT(ans = allocVector(VECSXP, n)); for(i = 0; i < n; i++) { defineVar(install("x"), VECTOR_ELT(list, i), rho); SET_VECTOR_ELT(ans, i, eval(expr, rho)); } I'm trying to understand this code beyond just copying it, and don't find definitions for many of the calls. PROTECT and SEXP have been well discussed previously in the document, but what exactly are R_len_t defineVar install VECTOR_ELT SET_VE...
2006 Dec 24
2
FW: Passing lists from R to C, extracting elements, and sending lists back again
...run the code below, the compiler (R CMD SHLIB sexp1.c) gives me: -bash-3.00$ R CMD SHLIB sexp1.c gcc -I/usr/lib64/R/include -I/usr/lib64/R/include -I/usr/include -I/usr/local/include -fpic -O2 -g -c sexp1.c -o sexp1.o sexp1.c: In function `invMatList': sexp1.c:37: warning: passing arg 3 of `SET_VECTOR_ELT' from incompatible pointer type gcc -shared -L/usr/local/lib64 -o sexp1.so sexp1.o -L/usr/lib64 -lgsl -lgslcblas -L/usr/lib -L/usr/lib64/R/lib -lR So, not only would it be helpful to understand how to solve this specific problem, but I would greatly appreciate some general guidance on how to...