search for: getattrib

Displaying 20 results from an estimated 59 matches for "getattrib".

2000 Jul 12
1
getAttrib() and setAttrib()
Hello: I am looking at "Writing R Extensions", subsection 3.6.4, using R 1.1.0, under NT4.0, with VC++ 6.0. Under these conditions I can use the first method given for coding the out() function, but not the second, which uses getAttrib() and setAttrib(). I hope that someone will tell me how this second method can also be made to work. Details follow, for anyone kind enough to help. I include the actual code lifted from the manual, so that you can compile, dyn.load() and tell me that it works fine for you! The R function of i...
2003 May 09
4
getAttr problem
Hi all, It seems that getAttr doesn't return "names" attribute properly as in getAttrib(x, R_NamesSymbol)); If you look at section 4.7.4 in "Writing R Extensions", the second example of SEXP out(SEXP, SEXP) returns NULL for the names attribute of the outer product. This is true for R 1.7.0 on both Win2000 with mingw and Redhat 9.0 with gcc. Is there something I am miss...
2000 Sep 07
1
getAttrb - Solved
Hi, I changed INTEGER(getAttrib(shape,mkChar("nParts")))[0] to INTEGER(getAttrib(shape,mkString("nParts")))[0] and now it works fine. Nicholas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send &quo...
2006 Aug 03
1
question about dll crashing R
.......) seperately more than two tims it crashes R. For the most part I am doing matirx multiplies using EXP matrixprod (SEXP x , SEXP y ) { int nrx , ncx , nry , ncy , mode; SEXP xdims , ydims , ans ; char *transa = "N" , *transb = "N" ; double one = 1.0 , zero = 0.0 ; xdims = getAttrib (x , R_DimSymbol ) ; ydims = getAttrib (y , R_DimSymbol ) ; mode = REALSXP; nrx = INTEGER( xdims ) [ 0 ] ; ncx = INTEGER( xdims ) [ 1 ] ; nry = INTEGER( ydims ) [ 0 ] ; ncy = INTEGER( ydims ) [ 1 ] ; PROTECT( ans = allocMatrix (mode, nrx , ncy ) ) ; F77_CALL(dgemm) ( transa , transb , &nrx , &a...
2009 Mar 17
1
question on "row.names" attribute of dataframe when called from a compiled package
...is in fact a vector of INTSXP? > .Call("print_class_of_rownames", x, package = "test") length(x): 10 TYPEOF(x): 13 R_ClassSymbol is null. NULL > is this the intended behaviour? -Whit here is my test code: SEXP print_class_of_rownames(SEXP dataframe_sexp) { SEXP x = getAttrib(dataframe_sexp,install("row.names")); cout << "length(x): " << length(x) << endl; cout << "TYPEOF(x): " << TYPEOF(x) << endl; if(getAttrib(x, R_ClassSymbol)==R_NilValue) { cout << "R_ClassSymbol is null." &l...
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.
2019 Nov 01
4
[External] R C api for 'inherits' S3 and S4 objects
...> C api so it can be achieved for S4 classes with no risk of allocation. > > For reference mentioned functions below. Thank you. > > Jan Gorecki > > > > // S3 inheritance > > bool INHERITS(SEXP x, SEXP char_) { > > SEXP klass; > > if (isString(klass = getAttrib(x, R_ClassSymbol))) { > > for (int i=0; i<LENGTH(klass); i++) { > > if (STRING_ELT(klass, i) == char_) return true; > > } > > } > > return false; > > } > > // S4 inheritance > > bool Rinherits(SEXP x, SEXP char_) { > > SEXP vec...
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
...CT(dim = allocVector(INTSXP, 2)); INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny; setAttrib(ans, R_DimSymbol, dim); *** It is safe to do UNPROTECT(1) for 'dim' already here, correct? *** PROTECT(dimnames = allocVector(VECSXP, 2)); SET_VECTOR_ELT(dimnames, 0, getAttrib(x, R_NamesSymbol)); SET_VECTOR_ELT(dimnames, 1, getAttrib(y, R_NamesSymbol)); setAttrib(ans, R_DimNamesSymbol, dimnames); UNPROTECT(3); return(ans); } Thanks /Henrik
2008 Apr 10
1
Computing time when calling C functions - why does an extra function call induce such an overhead?
...xtra function call to mysolve2? I am on windows XP using R 2.6.1 Best regards S?ren SEXP mysolve1(SEXP Ain, SEXP Bin, SEXP tolin) { int *Adims, *Bdims; double tol = asReal(tolin); SEXP A, B; PROTECT(A = duplicate(Ain)); PROTECT(B = duplicate(Bin)); Adims = INTEGER(coerceVector(getAttrib(A, R_DimSymbol), INTSXP)); Bdims = INTEGER(coerceVector(getAttrib(B, R_DimSymbol), INTSXP)); int nrA, ncB; double *Ap, *Bp; nrA = Adims[0]; ncB = Bdims[1]; Ap = REAL(A); Bp = REAL(B); /* int info, *ipiv = (int *) R_alloc(nrA, sizeof(int)); */ /* F77_CALL(dgesv)(...
2009 Jan 05
1
can't get names of R_env
...nd hash table (NULL or a VECSXP). A frame is a tagged pairlist with tag the symbol and CAR the bound value." But I'm having troubles accessing the data. I've written a small function called printNames that looks like ----------------------- void printNames(SEXP list){ SEXP names = getAttrib(list, R_NamesSymbol); int i; Rprintf("List is of length:%d\n",length(list)); for (i = 0; i < length(list); i++) Rprintf("name of id:%d\t%s\n",i,CHAR(STRING_ELT(names, i))); } ----------------------- This is basicly just a copy of ----------------------- stat...
2008 May 06
3
a R_PV problem
Dear all, When using gdb to debug my C code, I use R_PV to show the content of SEXP variables: SEXP sexp; // it is a data.frame SEXP colNames = getAttrib(sexp, R_NameSymbol); A strange thing is that after halting the program: (gdb) p R_PV(colNames) does not show the content of colNames. I am positive my code is right because if I insert "PrintValue(colNames);" in the c code, it will print the right value. My debug result shows that th...
2019 Nov 01
3
R C api for 'inherits' S3 and S4 objects
...ly not possible for S4 classes. I would kindly request new function in R C api so it can be achieved for S4 classes with no risk of allocation. For reference mentioned functions below. Thank you. Jan Gorecki // S3 inheritance bool INHERITS(SEXP x, SEXP char_) { SEXP klass; if (isString(klass = getAttrib(x, R_ClassSymbol))) { for (int i=0; i<LENGTH(klass); i++) { if (STRING_ELT(klass, i) == char_) return true; } } return false; } // S4 inheritance bool Rinherits(SEXP x, SEXP char_) { SEXP vec = PROTECT(ScalarString(char_)); SEXP call = PROTECT(lang3(sym_inherits, x, vec));...
1997 Nov 28
3
R-alpha: Problems with dimnames and names
...7bit Content-Disposition: attachment; filename="apatch" diff -ur R-0.50-a4/src/main/cov.c R-0.50-a4.patched/src/main/cov.c --- R-0.50-a4/src/main/cov.c Sun Nov 24 23:43:05 1996 +++ R-0.50-a4.patched/src/main/cov.c Fri Nov 28 11:21:23 1997 @@ -390,7 +390,7 @@ } if(isNull(y)) { x = getAttrib(x, R_DimNamesSymbol); - if(!isNull(x) && !isNull(CADR(x))) { + if(ncx > 1 && !isNull(x) && !isNull(CADR(x))) { PROTECT(ind = allocList(2)); CAR(ind) = CADR(x); CADR(ind) = CADR(x); @@ -401,7 +401,7 @@ else { x = getAttrib(x, R_DimNamesSymbol); y = ge...
2006 Jun 22
2
.Call and data frames
...re numbers, but when there is a column of strings I have a problem. On the C-side the function 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 i...
2006 Mar 09
0
When calling external C-function repeatedly I get different results; can't figure out why..
...= "N"; double one = 1.0, zero = 0.0; F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one, x, &nrx, y, &nry, &zero, z, &nrx); } SEXP trProd2(SEXP x, SEXP y) { int nrx, ncx, nry, ncy, mode, i; SEXP xdims, ydims, ans, ans2, tr; xdims = getAttrib(x, R_DimSymbol); ydims = getAttrib(y, R_DimSymbol); mode = REALSXP; nrx = INTEGER(xdims)[0]; ncx = INTEGER(xdims)[1]; nry = INTEGER(ydims)[0]; ncy = INTEGER(ydims)[1]; PROTECT(ans = allocMatrix(mode, nrx, ncy)); PROTECT(ans2 = allocMatrix(mode, nrx, ncy)); PROTECT(tr = allocVec...
2004 Oct 02
1
RCC compatibility patch
Would you consider the following patch to eval.c to allow compatibility with RCC? (It's in the applyClosure function.) @@ -432,6 +432,14 @@ SEXP f, a, tmp; RCNTXT cntxt; +#ifdef RCC + SEXP comp; + PROTECT(comp = getAttrib(op, install("RCC_CompiledSymbol"))); + if (comp != R_NilValue) /* compiled version exists */ + op = comp; + UNPROTECT(1); +#endif /* RCC */ + /* formals = list of formal parameters */ /* actuals = values to be bound to formals */ /* arglist = the tagged list...
2006 Oct 15
1
Feature request: names(someEnv) same as ls(someEnv)
Hi, I would be nice if names() returned the equivalent of ls() for environments. --- a/src/main/attrib.c +++ b/src/main/attrib.c @@ -687,6 +687,8 @@ SEXP attribute_hidden do_names(SEXP call s = CAR(args); if (isVector(s) || isList(s) || isLanguage(s)) return getAttrib(s, R_NamesSymbol); + if (isEnvironment(s)) + return R_lsInternal(s, 0); return R_NilValue; } + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
2013 Sep 27
0
SET_NAMED in getattrib0
Can someone please set me straight on why getattrib0 calls SET_NAMED on the SEXP it returns? For example the line : SET_NAMED(CAR(s), 2); appears near the end of getattrib0 here : https://svn.r-project.org/R/trunk/src/main/attrib.c <https://svn.r-project.org/R/trunk/src/main/attrib.c> getattrib() is just reading the value. Shouldn&...
2011 Dec 28
1
external pointers
...riting R Extensions", I've noted that "external pointers should only be used as part of an object with normal semantics, for example an attribute or an element of a list." So I've written up a workable C function as such: SEXP my_c_function(SEXP param) { SEXP temp = getAttrib(param, install("ptr_attribute")); void * ptr = R_ExternalPtrAddr(temp); ... // do useful things with ptr } I can pass my_c_function() an object with "normal" semantics (such as an integer vector), where the external pointer object is a parameter named "ptr_attr...
2006 Mar 09
0
When calling external C-function repeatedly I get differentresults; can't figure out why..
...zero = 0.0; > F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one, > x, &nrx, y, &nry, &zero, z, &nrx); } > > SEXP trProd2(SEXP x, SEXP y) > { > int nrx, ncx, nry, ncy, mode, i; > SEXP xdims, ydims, ans, ans2, tr; > xdims = getAttrib(x, R_DimSymbol); > ydims = getAttrib(y, R_DimSymbol); > mode = REALSXP; > nrx = INTEGER(xdims)[0]; > ncx = INTEGER(xdims)[1]; > nry = INTEGER(ydims)[0]; > ncy = INTEGER(ydims)[1]; > PROTECT(ans = allocMatrix(mode, nrx, ncy)); > PROTECT(ans2 = allocMatrix(mod...