search for: new_character

Displaying 16 results from an estimated 16 matches for "new_character".

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....
2007 Jan 23
2
is it necessary to always register C routines with R_registerRoutines?
...I'm studying .Call interface. I have adapted the example from page 77 of r-exts.pdf, however, it crashes R. I use MingW as recommended by Duncan Murdoch. Please, tell me what I am missing. The code is below. Thank you. SEXP snns_getVersion(void) {SEXP version; char *v; PROTECT(version=NEW_CHARACTER(15)); v=CHARACTER_POINTER(version); strcpy(v,krui_getVersion()); UNPROTECT(1); return version; } > sessionInfo() R version 2.4.1 (2006-12-18) i386-pc-mingw32 locale: LC_COLLATE=Russian_Russia.1251;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=Russian_Russia.1251;LC_NUMERIC=C;LC_TIME=Russi...
2006 Aug 21
1
return tree from .Call
...help will be greatly appreciated! SEXP list ; PROTECT( list = allocVector(VECSXP, tree->size) ) ; for( i = 0; i < tree->size; ++i ){ SEXP node, tree_double, tree_char, tree_int, tree_voidPTR ; PROTECT( tree_double = NEW_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,...
2004 Mar 06
2
.Call: is new attribute of protected object auto-protected
Hi, I have an SEXP obj in a C function called via .Call(). The obj is protected (in fact it is an argument to .Call and therefore automatically protected). If I set an attribute of obj does the attribute become protected too? Here is an example SEXP foo(SEXP obj) { SET_NAMES(obj, NEW_CHARACTER(3)); /* are names protected or not? */ ... } Thanks, Vadim [[alternative HTML version deleted]]
2008 Jan 29
2
Problem with new("externalptr")
...gt; > new("environment") <environment: 0xc51248> But for new("externalptr"), I had to use the following C routine: SEXP sexp_address(SEXP s) { SEXP ans; char buf[40]; snprintf(buf, sizeof(buf), "%p", s); PROTECT(ans = NEW_CHARACTER(1)); SET_STRING_ELT(ans, 0, mkChar(buf)); UNPROTECT(1); return ans; } Then I get: > .Call("sexp_address", new("externalptr")) [1] "0xde2ce0" > .Call("sexp_address", new("externalptr")) [1] "0xde2ce0&quo...
2000 Apr 01
1
Bug ? mine or ? in R core
...]; long j=1,k=1, /* row counters*/ buffsize=(long)REAL(bs)[0], /* prealloc if row count NA*/ length,offset,t_offset; /* counts into output buf*/ NCOLS=1; PROTECT(ans=NEW_LIST(2)); /*create answer [0] = data, [1]=stat */ PROTECT(stat=NEW_INTEGER(1)); /* numeric status vector */ PROTECT(data=NEW_CHARACTER(buffsize)); while(1){ for (i=1; i<= NCOLS; i++){ offset=((i-1)*maximum)+(j-1); } DBG(2,"writing to data"); STRING(data)[offset]=COPY_TO_USER_STRING("Some dummy data"); if(offset +NCOLS >= buffsize){ DBG(1,"reallocating space"); length=length(d...
2003 Dec 10
0
C++: SET_LENGTH() Over Many Iterations?
...) { Rprintf(" ** Iteration %d:\n", i + 1); if (full_alloc) INTEGER_POINTER(int_vect)[i] = i; else PUSH_BACK_INTEGER(int_vect, i); } SEXP out, names, cls; PROTECT(out = NEW_LIST(1)); SET_VECTOR_ELT(out, 0, int_vect); PROTECT(names = NEW_CHARACTER(1)); SET_STRING_ELT(names, 0, COPY_TO_USER_STRING("integer.vector")); SET_NAMES(out, names); PROTECT(cls = NEW_CHARACTER(1)); SET_STRING_ELT(cls, 0, COPY_TO_USER_STRING("pushback")); classgets(out, cls); UNPROTECT(6); return out; } </CPP Code&g...
2003 Oct 04
3
More questions about R extension programming
On Fri, 2003-10-03 at 17:01, Rajarshi Guha wrote: > Hi, > I'm using a package that has a number of formats. I have C code to > parse these formats the results of which are generally integer arrays. > > I would like to utilize these modules in R rather than writing R code to > read in these files (and also to learn about R extensions). Thanks for the pointers to the above
2004 Aug 18
3
R as shared library
...nsole = Rapache_WriteConsole; /* load source(). I assume this is appropriate. I could always move this to the code that handles the requst */ PROTECT(R_source_fun = allocVector(LANGSXP, 2)); SETCAR(R_source_fun, Rf_install("source")); SETCAR(CDR(R_source_fun), R_source_arg = NEW_CHARACTER(1)); Then each request is serviced by the following code: /* r is apache request, r->filename is url translated to apsolute path to filename */ SET_STRING_ELT(R_source_arg, 0, COPY_TO_USER_STRING(r->filename)); errorOccurred=1; /* R code: source(filename) */ val = R_tryEval(R...
2003 Dec 12
3
C++: Appending Values onto an R-Vector.
Hi folks. I posted this question a few days ago, but maybe it got lost because of the code I included with it. I'm having a problem using the SET_LENGTH() macro in an R extension I'm writing in C++. In a function within the extension I use SET_LENGTH() to resize R vectors so as to allow the concatenation of single values onto the vectors -- it's a "push back" function to
2004 Apr 06
1
A question about embedded R
Hello everyone, I met a strange problem when I call R expression from C++, here is the details: I edited a function eval_R_command(); double eval_R_command(const char *funcName) { SEXP exp,e; ParseStatus status = PARSE_OK; int i,n; double val; PROTECT(exp=NEW_CHARACTER(1)); SET_STRING_ELT(exp, 0, COPY_TO_USER_STRING(funcName)); PROTECT(e = R_ParseVector(exp, 1, &status)); n = GET_LENGTH(e); for(i = 0; i < n ; i++) val = (double)REAL(eval(VECTOR_ELT(e,i), R_GlobalEnv))[0]; UNPROTECT(2); return(val); } Then if i call wit...
2006 Oct 31
1
Some R questions
Hi all, I am working with some large data sets (1-4 GB) and have some questions that I hope someone can help me with: 1. Is there a way to turn off garbage collector from within C interface ? what I am trying to do is suck data from mysql (using my own C functions) and I see that allocating each column (with about 1-4 million items) takes between 0.5 and 1 seconds. My
2004 Oct 08
2
R-2.0.0 findVar and findFun question
Dear all, when working on a project with embedded R, I found out that R-2.0.0 causes a problem where older versions worked OK. Rf_findVar(...) causes the following error when used to find a generic function (such as print): fun = Rf_findVar(...); R_tryEval(fun, ...); Error in function (object, ...) : Invalid generic function in usemethod Alternatively, using Rf_findFun(...) seems OK in this
2005 Jul 15
3
Passing character strings from C code to R
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 relevant part of the code: 1 PROTECT(Ret = allocVector(INTSXP, n)); 2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */ 3 for(i=0; i<n; i++) ret[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n
2005 Jul 15
3
Passing character strings from C code to R
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 relevant part of the code: 1 PROTECT(Ret = allocVector(INTSXP, n)); 2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */ 3 for(i=0; i<n; i++) ret[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n
2009 Sep 16
2
I want to get a reference to this time series object
I'm trying to get a reference to this object in C SWX.RET[1:6,c("SBI,"SPI","SII")] While i am able to access and use a plain SWX.RET object, I'm getting confused on how to create an object with the array subscripts like above. Here is what I tried to do. It doesn't work because "[" is obviously not an operation or function on SWX.RET. So how do I