search for: setattrib

Displaying 20 results from an estimated 39 matches for "setattrib".

Did you mean: getattrib
2005 Mar 16
1
.Call - applying setAttrib(x, R_DimSymbol, s) to a matrix being an element of a list
Dear R developers, I am writing some C code that loads multiple images into a list of R matrices. The whole R object is created within the C code. To simplify coding, elements of the list are first created as vectors and then converted to corresponding matrices using setAttrib(x, R_DimSymbol, s). Generally the code works fine except for one detail. Applying setAttrib sets ALL elements (matrices) in the list to the same size, namely to the one last applied, doesn't matter if other matrices are larger or smaller. The command is applied to an element, not to the who...
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 interest is the o...
2014 Oct 31
3
ScalarLogical and setAttrib
...al as well? For example: the 'test1' function below returns FALSE and 'test2' returns FALSE with an attribute: library(inline) test1 <- cfunction(body = 'return ScalarLogical(0);') test2 <- cfunction(body = ' SEXP success = PROTECT(ScalarLogical(0)); setAttrib(success, install("foo"), mkString("bar")); UNPROTECT(1); return success; ') However after running test2(), then test1() will also return the attribute: > test1() [1] FALSE > test2() [1] FALSE attr(,"foo") [1] "bar" > tes...
2014 Jun 24
2
using C code to create data frame but always return as list
...alcmd);  jl_value_t* onesymbol;  if (jl_is_array(ret))  {   PROTECT(names=allocVector(STRSXP,collen));   for (i=0;i<jl_array_len(ret);i++)   {     onesymbol=jl_arrayref((jl_array_t*)ret,i);    if (jl_is_symbol(onesymbol))     SET_STRING_ELT(names,i,mkChar(((jl_sym_t*)onesymbol)->name));   }   setAttrib(ans,R_NamesSymbol,names);   UNPROTECT(1);  }   //set row names  sprintf(evalcmd,"size(%s,1)",dfname);  jl_value_t* rows=jl_eval_string(evalcmd);  int rowlen=jl_unbox_long(rows);  PROTECT(rownames=allocVector(INTSXP,rowlen));  for (i=0;i<rowlen;i++)   INTEGER(rownames)[i]=i+1;  setAttri...
2004 Feb 11
1
.Call setAttrib(ans,R_DimSymbol,dim); Crashes.
...t fine. SEXP ans,dim; PROTECT(ans = NEW_NUMERIC(count*2)); memcpy(NUMERIC_POINTER(ans),result,count*sizeof(double)); memcpy(&(NUMERIC_POINTER(ans)[count]),occur,count*sizeof(double)); /** PROTECT(dim=NEW_INTEGER(2)); INTEGER_POINTER(dim)[0]=2; INTEGER_POINTER(dim)[1]=count; setAttrib(ans,R_DimSymbol,dim); */ UNPROTECT(7); If I uncomment the lines 5 to 8 than all is working fine four small count's (tested 10,20). But if the result is an array with about 2000 entries R crashes vicious and violently with the lax comment Process R trace trap at Wed Feb 11 13:55:45 2004 An...
1999 May 11
1
another multivariate ts bug
I think this is another one of the same kind of bugs in ts: Version 0.64.1 (May 8, 1999) ... > z <- ts(matrix(1:20,10,2), start=c(1969,1), frequency=12) > (z > 5) | (z < 2) Error: invalid time series parameters specified > Paul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read
2005 Jul 15
3
Passing character strings from C code to R
...n>0) { // and it actually have some length 9 Rprintf(" '%s' %i\n", comment, n); 10 PROTECT(Str = allocString(n+1)); 11 str = CHAR(STRING_ELT(Str, 0)); 12 strcpy(str, comment); 13 Rprintf(" '%s' %i\n", str, n); 14 setAttrib(Ret, install("comm"), Str); 15 i=2; 16 } 17 Free(comment); 18 } 20 UNPROTECT(i); Print statement in line 9 gives right results, but program crashes before print statement in line 13. Any ideas to what am I doing wrong? Jarek ====================================...
2005 Jul 15
3
Passing character strings from C code to R
...n>0) { // and it actually have some length 9 Rprintf(" '%s' %i\n", comment, n); 10 PROTECT(Str = allocString(n+1)); 11 str = CHAR(STRING_ELT(Str, 0)); 12 strcpy(str, comment); 13 Rprintf(" '%s' %i\n", str, n); 14 setAttrib(Ret, install("comm"), Str); 15 i=2; 16 } 17 Free(comment); 18 } 20 UNPROTECT(i); Print statement in line 9 gives right results, but program crashes before print statement in line 13. Any ideas to what am I doing wrong? Jarek ====================================...
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
...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_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));...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
...the vector as a names */ /* attribute. Note that this function mutates x. */ /* Duplication should occur before this is called. */ SEXP DropDims(SEXP x) { SEXP dims, dimnames, newnames = R_NilValue; int i, n, ndims; PROTECT(x); dims = getAttrib(x, R_DimSymbol); [... SNIP ....] setAttrib(x, R_DimNamesSymbol, R_NilValue); setAttrib(x, R_DimSymbol, R_NilValue); setAttrib(x, R_NamesSymbol, newnames); [... SNIP ....] return x; } Well, at least there's a warning comment with that one. But it does show .Call allows call by reference. Why allow it, though? DropDims could c...
2019 Jul 11
2
Convert STRSXP or INTSXP to factor
...INTSXP to factor. The idea would be to do in C something similar to the "factor" function (example below): > letters[1:5] # [1] "a" "b" "c" "d" "e" > factor(letters[1:5]) # [1] a b c d e # Levels: a b c d e There is the function setAttrib the levels of a SXP however when returned to R the object is of type character not factor. Ideally what i would like to return from the C function is the same output as above when the input is of type character. Please let me if you need more informations. Thank you Best regards Morgan [[alterna...
2014 Apr 03
1
question regarding lang2 command in C
Hi , I am asking too many questions , sorry for that . I am creating a data frame in C itself , reading a table . The data frame calling code looks like this ====================================== *PROTECT(dfm=lang2(install("data.frame"),df));* *SEXP res = PROTECT(eval(dfm,R_GlobalEnv));* UNPROTECT(2); return res; ================================== It works fine , now the problem
2006 Nov 17
1
Manipulating R lists in C
...or( STRSXP,1 ) ); SET_STRING_ELT( volumeStr, 0, mkChar("volume") ); // assign string objects to vector SET_VECTOR_ELT( dimnames, 0, typeStr ); SET_VECTOR_ELT( dimnames, 1, priceStr); SET_VECTOR_ELT( dimnames, 2, volumeStr ); // assign vector to original list of data setAttrib( priceList, R_DimNamesSymbol, dimnames ); <----- I think this is wrong but I don;t know what it should be ===========END EXTRACT=============== -- Dr. Thomas McCallum Systems Architect, Level E Limited ETTC, The King's Buildings Mayfield Road, Edinburgh EH9 3JL, UK Work +44 (0) 131 472...
2003 Sep 05
1
Problem with S4 slots in C code (PR#4073)
...or(STRSXP, 5)); SET_STRING_ELT(names, 0, mkChar("age")); SET_STRING_ELT(names, 1, mkChar("year")); SET_STRING_ELT(names, 2, mkChar("sex")); SET_STRING_ELT(names, 3, mkChar("season")); SET_STRING_ELT(names, 4, mkChar("area")); setAttrib(dimnames, R_NamesSymbol, names); setAttrib(v, R_DimNamesSymbol, dimnames); //Set data REAL(v)[0] = 2; //Set slot SET_SLOT(FLQuant, install(".Data"), v); UNPROTECT(10); return FLQuant; } --please do not edit the information bel...
2005 Jul 15
0
[R] Passing character strings from C code to R
...r you to browse. There is even a shortcut that manages the PROTECTS, Str = mkString(comment); (That allocString and mkString return different types indicate why I wrote `whatever that is': the term is too loose to be useful.) So you could just have if(comment && strlen(comment) setAttrib(Ret, install("com"), mkString(comment)); if(comment) Free(comment); On Fri, 15 Jul 2005, Tuszynski, Jaroslaw W. wrote: > Hi, > > I have a C code which produces array of integers and potentially a > string, and I have problems passing the string out. Here is the > relev...
2009 Mar 30
1
Setting the names attribute of a list?
...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
2019 Jul 15
0
Convert STRSXP or INTSXP to factor
...r at this point in the R function). Getting this to be performant would probably be annoying but is doable (e.g., via a hash table or some such) 3. Do classgets on the the output vector to make it a factor (this will set the object bit so you don't need to do that separate) 4. do setAttrib on the output vector to set the levels attribute (which now needs to be a STRSXP rather than, e.g., an array of const char*) 5. Return the output vector Personally, unless there was a really compelling reason not to, I'd just do the create and evaluate an R-level call thing instead....
2014 Mar 06
1
Create dataframe in C from table and return to R
...)); 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) } ------------------------------------------------------------------------ It wor...
2005 Nov 07
3
R thread safe
...ist, i), rho); omp_unset_lock(&lck); /* do computational kernel in parallel */ alocal = eval(expr, rho); omp_set_lock(&lck); SET_VECTOR_ELT(ans, i, alocal); UNPROTECT(1); omp_unset_lock(&lck); } setAttrib(ans, R_NamesSymbol, getAttrib(list, R_NamesSymbol)); UNPROTECT(1); return(ans); } *********** The code works fine using one thread and breaks currently down with 2 threads. I am using a recent R distribution and the complete R code is compile with "-openmp" and the Paths...
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