search for: vector_elt

Displaying 20 results from an estimated 112 matches for "vector_elt".

2012 May 07
0
R CMD check, interfacing c++ linking errors
...f) { multimap<double,treeNode,greater<double> > treeMap; multimap<double,treeNode,greater<double> >::iterator it_tM; int l =LENGTH(membership); //Rprintf("beleptunk"); int p = 0; map<int,int> degrees; for(int i=0;i < l;i++){ SEXP members = VECTOR_ELT(membership,i); //Rprintf("%d\n",Nmembers); SEXP membersSXP = VECTOR_ELT(members,0); SEXP sizesxp = VECTOR_ELT(members,1); double* sizevc = REAL(sizesxp); double size = sizevc[0]; int Nmembers = LENGTH(membersSXP); treeNode tmp_tN; //Rprintf("the size of the module is: %f\n...
2012 May 08
0
R CMD check, c++ source linking errors
...f) { multimap<double,treeNode,greater<double> > treeMap; multimap<double,treeNode,greater<double> >::iterator it_tM; int l =LENGTH(membership); //Rprintf("beleptunk"); int p = 0; map<int,int> degrees; for(int i=0;i < l;i++){ SEXP members = VECTOR_ELT(membership,i); //Rprintf("%d\n",Nmembers); SEXP membersSXP = VECTOR_ELT(members,0); SEXP sizesxp = VECTOR_ELT(members,1); double* sizevc = REAL(sizesxp); double size = sizevc[0]; int Nmembers = LENGTH(membersSXP); treeNode tmp_tN; //Rprintf("the size of the module is: %f\n&...
2012 May 08
1
R CMD check linking errors, when interfacing c++
...f) { multimap<double,treeNode,greater<double> > treeMap; multimap<double,treeNode,greater<double> >::iterator it_tM; int l =LENGTH(membership); //Rprintf("beleptunk"); int p = 0; map<int,int> degrees; for(int i=0;i < l;i++){ SEXP members = VECTOR_ELT(membership,i); //Rprintf("%d\n",Nmembers); SEXP membersSXP = VECTOR_ELT(members,0); SEXP sizesxp = VECTOR_ELT(members,1); double* sizevc = REAL(sizesxp); double size = sizevc[0]; int Nmembers = LENGTH(membersSXP); treeNode tmp_tN; //Rprintf("the size of the module is: %f\n&...
2020 Jun 16
1
[External] numericDeriv alters result of eval in R 4.0.1
Dear all As far as I could trace, looking at the function C function numeric_deriv, this unwanted behavior comes from the inner most loop in, at the very end of the function, for(i = 0, start = 0; i < LENGTH(theta); i++) { for(j = 0; j < LENGTH(VECTOR_ELT(pars, i)); j++, start += LENGTH(ans)) { SEXP ans_del; double origPar, xx, delta; origPar = REAL(VECTOR_ELT(pars, i))[j]; xx = fabs(origPar); delta = (xx == 0) ? eps : xx*eps; REAL(VECTOR_ELT(pars, i))[j] += rDir[i] * delta; PROTECT(ans_del = eval(expr, rho)); if(!is...
2010 Aug 31
0
VECTOR_ELT() can only be applied to a 'list', not a 'integer (gstat problem)
...t when attempting to fit a regression-kriging model to my data. I have successfully carried out a stepwise regression on my data and I have the model residuals. However when I try to apply a variogram to the residuals I get the following error message; *>>>Error in grid.newpage() : * * VECTOR_ELT() can only be applied to a 'list', not a 'integer'<<<<* * * * * I wonder if it is something as simple as changing the format of my model residuals because when the residuals are checked they are in ‘numeric’ format rather than ‘list’. Please excuse my ignorance if t...
2006 Jul 11
2
Converting SEXP to primitive C types
I'm new to R development, so this may be a trivial question. In C, How do you convert a SEXP value returned by an R function to a primitive C type (int, double, char, array, etc.)? I've tried using the INTEGER(x), VECTOR_ELT(x,i), and similar functions found in /src/ include/Rinternals.h, but doing so results in incorrect results or a seg-fault. For example, I modified /tests/Embedding/Rerror.c so that it tries to print the value returned by the function defined in error.R: val = Test_tryEval(e, &errorOccurr...
2007 May 29
1
Use of Rf_duplicate
...the passed, I got some odd results of the original lists being changed (when I didn't want them to be). So suppose that x is the list that is passed from R to the C code. Is there any (conceivable) reason that I might want to do something like PROTECT(y = duplicate(x)); PROTECT(z = duplicate(VECTOR_ELT(y,2))); Instead of PROTECT(y=duplicate(x)); PROTECT(z = VECTOR_ELT(y,2)); And if I did create a duplicate, is there a way to destroy it manually before the end of the function, rather than rely on on the R garbage collector? Thanks, Michael Michael Braun Assistant Professor of Marketing...
2003 Dec 17
1
Accessing row and col names of SEXP objects
...de I'm using to grab the jth column name and print it, but the colnames I'm getting are garbage. None of the following are working. void printInfo(SEXP ts) { int j; for (j=0; j<col; j++) { printf("%s\n",CHAR(STRING_ELT(GetColNames(ts), j))); printf("%s\n",CHAR(VECTOR_ELT(GetColNames(ts), j))); printf("%s\n",CHARACTER_DATA(STRING_ELT(GetColNames(ts), j))); printf("%s\n",CHARACTER_DATA(VECTOR_ELT(GetColNames(ts), j))); } } Here is the object I'm passing in: tmp <- matrix(rnorm(100),ncol=5) colnames(tmp) <- c("tmp",&qu...
2006 Jul 18
2
send a list from R to C
...problems to give a character vector form R to C. But, if I combine real and strings in a list then I don't know the correct syntax. I try it with following (an example): SEXP writeFile(SEXP headerR){ Image *SaveImage; PROTECT(headerR = AS_VECTOR(headerR)); SaveImage->Xmin = (float) REAL(VECTOR_ELT(headerR, 0))[0]; SaveImage->Ymin = (float) REAL(VECTOR_ELT(headerR, 0))[1]; strcpy(SaveImage->Description, CHAR(STRING_ELT(headerR, 1))); } where typedef struct { float Xmin; float Ymin; char Description[80]; } Image; But with this form the characters are doesn't correct (in th...
2006 Jun 22
2
.Call and data frames
...ction looks like: SEXP myfunc(SEXP df), and it is called with a dataframe from the R side with: .Call("myfunc", somedataframe) On the C side (actually C++ side) I use code like this: SEXP colnames = getAttrib(df, R_NamesSymbol) cname = string(CHAR(STRING_ELT(colnames,i)) SEXP coldata = VECTOR_ELT(df,i) (data for i-th column) if(isReal(colData)) x = REAL(colData)[j]; else if(isInteger(colData)) i = INTEGER(colData)[j]; else if(isString(colData)) s = CHAR(STRING_ELT(colData,j)) The problem is that the last test (isString) never passes, even when I pass in a frame for which one or...
2006 May 17
1
protect/unprotect howto in C code
...uestions on the use of PROTECT and UNPROTECT, which I could not figure out: - which objects have to be protected, namely, if the code is something like: SEXP fun, e; /* get the expression e ... */ fun = eval(e, R_GlobalEnv); /* or like this?: PROTECT(fun = eval(e, R_GlobalEnv)); */ PROTECT(fun = VECTOR_ELT(fun, 1)); /* do more things with fun ... */ does one need to protect the result of a call to 'eval' immediately? And how about R_tryEval? While searching for code examples in the sources, I found both protected evals and fewer non-protected. - Can someone give a hint (or some documents)...
2023 Mar 23
1
`dendrapply` Enhancements
...it may make sense to move lang3() out of the loop and reuse the existing object by referring to the DEND_IND variable using its symbol, like it's done in the lapply() implementation. > The problem is, it seems like the returned value from `eval` is not > protected, whereas the value from VECTOR_ELT is (if the source list > is protected). My understanding is that this happens because > VECTOR_ELT just copies the pointer, whereas eval(?) calls R code, > which returns a copy of the object. That's right, `[[.dendrogram` returns a new object which is not protected, unlike the raw ele...
2018 Apr 19
3
R Bug: write.table for matrix of more than 2, 147, 483, 648 elements
...(in addition to "(R_xlen_t)nr * nc") will be sufficient for cases where nr and nc are in int range but their product can reach long vector limit: replace ??? tmp = EncodeElement2(x, i + j*nr, quote_col[j], qmethod, ??? ??? ??? ??? ??? &strBuf, sdec); by ??? tmp = EncodeElement2(VECTOR_ELT(x, (R_xlen_t)i + j*nr), 0, quote_col[j], qmethod, ??? ??? ??? ??? ??? &strBuf, sdec); Serguei
2001 Dec 03
0
Segfault in foreign:read.xport (PR#1192)
...ackage foreign (version 0.4-7). The culprit seems to be these lines in xport_read in SASxport.c: 590 } else { 591 c = strchr(tmpchar, ' '); 592 *c = '\0'; 593 SET_STRING_ELT(VECTOR_ELT(data, k), j, 594 (c == tmpchar) ? R_BlankString : 595 mkChar(tmpchar)); 596 } (gdb) print tmpchar $1 = 0xb63674 "0502" (gdb) print c $2 = 0x0 According to the solaris man pages,...
2010 Mar 11
1
Shrinking a List
...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, so can I a) is there a resize function for a VECSXP? if not b) can i just do something like SET_VECTOR_ELT(B,i, VECTOR_ELT(A,i)) instead of wrapping VECTOR_ELT(A,i) inside a call to Rf_duplicate (i will be UNPROTECTING A and B, though I will return B) I suppose I can do (b), since B (since it is being returned) is automatically protected and therefore all its elements will also be protected, correct?...
2002 Mar 02
1
accessing factor levels from C
Hi, I am trying to get information about factors from a C-program. As I see, the factors are basically integers with attribute ,,levels''. But unfortunately I am not been able to read the levels information. I am using: SEXP variable, levels; ... variable = VECTOR_ELT( data_frame, j); switch( TYPEOF( variable)) { case INTSXP: if( isFactor( VECTOR_ELT( data_frame, j))) { fvalue = INTEGER( variable)[i]; levels = STR_PTR( GET_LEVELS( variable)); .... but the variable levels is not an array of strings as I expected. I am probably doing somethi...
2005 Jan 31
2
type of list elements in .Call
...************************************* #include <iostream> #include <R.h> #include <Rinternals.h> using std::cout; using std::endl; extern "C" { SEXP printlst(SEXP lst); } SEXP printlst(SEXP lst) { for(int i=0; i<length(lst); i++) for(int j=0; j<length(VECTOR_ELT(lst, i)); j++) cout << INTEGER(VECTOR_ELT(lst, i))[j] << endl; return lst; } ************************************************* > dyn.load("foo.so") > .Call("printlst", list(c(1,2),c(3,4))) 0 1072693248 0 1074266112 [[1]] [1] 1 2 [[2]] [1] 3 4 If I...
2018 May 08
2
unlist errors on a nested list of empty lists
...tor function in src/main/apply.c, which looks like this: static Rboolean islistfactor(SEXP X) { int i, n = length(X); switch(TYPEOF(X)) { case VECSXP: case EXPRSXP: if(n == 0) return NA_LOGICAL; for(i = 0; i < LENGTH(X); i++) if(!islistfactor(VECTOR_ELT(X, i))) return FALSE; return TRUE; break; } return isFactor(X); } One of those deeply nested lists is length 0, so at the lowest level it returns NA_LOGICAL. But then it does C-style logical testing on the results. I think to C NA_LOGICAL counts as true, so at the n...
2020 Jun 15
2
numericDeriv alters result of eval in R 4.0.1
Dear R developers, I've run into a weird behavior of the numericDeriv function (from the stats package) which I also posted on StackOverflow (question has same title as this email, except for the version of R). Running the code bellow we can see that the numericDeriv function gives an error as the derivative of x^a wrt a is x^a * log(x) and log is not defined for negative numbers. However,
2000 Aug 09
2
GenGC changes
...vectors (and language objects) 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...