similar to: protect

Displaying 20 results from an estimated 5000 matches similar to: "protect"

2004 Mar 17
1
best methods for strings and structures?
I'm trying to generate an R interface for a library that's commonly used and I'm currently writing wrapper functions for file i/o and return an object (list?) that contains the elements of the C structure. For example, reading a file that contains: struct CONFIG_RECORD { char coeffs_filename[256]; char species_filename[256]; unsigned long
2001 Sep 10
1
not safe to return vector pointer
Hello All, I recently upgraded from R-1.1.1 to R-1.2.2. I have an R function that uses .Call() to return a list from C code. The C code has the form: SEXP function(SEXP var) { SEXP rlist ; PROTECT(rlist = NEW_LIST(3)) ; VECTOR_PTR(rlist)[0] = NEW_INTEGER(1) ; VECTOR_PTR(rlist)[1] = NEW_STRING(1) ; ... UNPROTECT(1) ; return(rlist) ; } When I try to
2003 Nov 18
1
How to return a big treelike list from .Call Interface (protect stack overflow)
I try to create a big treelike list structure using the RDefines/RInternal macros. The tree carries information at each node (attribute list) and at each leaf (vector). My understanding is that for each node I add to the binary tree I have to call PROTECT(newnode = NEW_LIST(2)); and cannot UNPROTECT before I return the whole tree. Same story for node attributes and leaf vectors. However, this
2006 Nov 17
1
Manipulating R lists in C
Hi, I have been studying the R manual on lists but cannot seem to create a simple R list in C - I keep on getting "'dimnames' applied to non-array" whenever I attempt to assign names to the list elements: Wanted output a list structure something like [ type="Bid", price=2.0, volume=1000 ] I can get up to a list of [ "Bid2, 2.0, 1000 ] But for the life of
2006 Aug 21
1
return tree from .Call
Hello: I was hoping to get some advice about how to return a tree (basically a linked list -- with each node containing a parent, left, and right node pointers) from a C routine back into R. Each node itself contains several attributes (a double, a char *, an int, and a void * ) Initially I was thinking I could just return to R a SEXP containing a pointer to the Root Node, but then realized
2005 Mar 16
3
Write Barrier: was: function-like macros undefined
Hi, Thank you to Duncan Murdoch for pointing to 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
2005 May 17
1
returning an empty list.
I would like to return an empty list from a C function. This I would do as: if (file.exists()) { /* do something */ } else { SEXP empty_list; PROTECT(empty_list = NEW_LIST(0)); UNPROTECT(1); return empty_list; } The PROTECT, UNPROTECT lines seemed like overkill to me, but as far as I understood the documentation this seemed like the correct usage. It seems like I could
2011 Jan 17
1
isoreg memory leak?
I believe there is a memory leak in isoreg in the current version of R, as I believe the following shows > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 120405 3.3 350000 9.4 350000 9.4 Vcells 78639 0.6 786432 6.0 392463 3.0 > for(k in 1:100) { + + y <- runif(10000) + isoreg(x,y) + } > rm(x) > rm(y) > gc() used (Mb) gc
2009 Sep 20
1
Return a list from a .Call but segfaults
Hello, I call a function via .Call passing to it a raw vector(D) and an integer(I) The vector is a series K1,KData1, V1,VData1, K2, KData2, ... where the integer K1 is the length of Data1 and similarly for Ki (wrt Datai)(similarly for V*) There 2*I such pairs( (Ki,KDatai), (Vi,VDatai)) The numbers Ki(and Vi) are written in network order. I am returning a list of I elements each element a
2023 Apr 29
1
Forcing a PROTECT Bug to Occur
I'm trying to learn about R's PROTECT system. To that end I've tried to create an example of C code that doesn't protect anything. I was hoping it would either segfault from trying to access deallocated memory, or maybe print out nonsense results because the unprotected memory got overwritten, but I can't make either happen. Here's my current code (all in R, using the
2016 Oct 24
3
typo or stale info in qr man
man for `qr` says that the function uses LINPACK's DQRDC, while it in fact uses DQRDC2. ``` The QR decomposition of the matrix as computed by LINPACK or LAPACK. The components in the returned value correspond directly to the values returned by DQRDC/DGEQP3/ZGEQP3 ```
2008 Jan 04
1
Evaluating R expressions from C
I am currently puzzled by a passage in the R Extensions manual, section 5.10: SEXP lapply(SEXP list, SEXP expr, SEXP rho) { R_len_t i, n = length(list); SEXP ans; if(!isNewList(list)) error("`list' must be a list"); if(!isEnvironment(rho)) error("`rho' should be an environment"); PROTECT(ans = allocVector(VECSXP, n));
2013 Aug 27
1
Error in simulation. NAN
Hi all, im triyng to implement a bayesian model with R and c++. I have a strange problem. I can't reproduce the error with a small script and then i post the original one. The problem is after the line for(MCMC_iter2=0;MCMC_iter2<thin;MCMC_iter2++) For the first 34 iterations all work fine, after, all the simulations of mu_acc_P return an "nan". If i delete the line
2009 Mar 30
1
Setting the names attribute of a list?
Hello, I have created a vector with 2 elements(see code below) I am calling this function many thousands of times (hundreds of thousands) after some time i get *** caught segfault *** 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
2018 Nov 15
2
STRING_IS_SORTED claims as.character(1:100) is sorted
If I have loaded the C code: SEXP altrep_STRING_IS_SORTED(SEXP x) { return ScalarInteger(STRING_IS_SORTED(x)); } and defined the function: issort <- function(x) .Call("altrep_STRING_IS_SORTED",x) I am seeing the following results in R 3.5.1/Linux: > issort(LETTERS) [1] NA > issort(as.character(1:100)) ## should return NA [1] 1 >
2013 Mar 03
1
Missing PROTECT in mkPRIMSXP ?
The Bioconductor build for a package DirichletMultinomial on R Under development (unstable) (2013-02-26 r62077) -- "Unsuffered Consequences" at http://bioconductor.org/checkResults/devel/bioc-LATEST/DirichletMultinomial/george2-buildsrc.html shows * creating vignettes ... ERROR ... Error: processing vignette ?DirichletMultinomial.Rnw? failed with diagnostics: chunk 21 (label
2014 Oct 31
3
ScalarLogical and setAttrib
Is it expected that attributes set on a LGLSXP created by ScalarLogical will apply to all future objects created by ScalarLogical 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 =
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
2007 Aug 03
2
How to properly finalize external pointers?
Dear R .Call() insiders, Can someone enlighten me how to properly finalize external pointers in C code (R-2.5.1 win)? What is the relation between R_ClearExternalPtr and the finalizer set in R_RegisterCFinalizer? I succeeded registering a finalizer that works when an R object containing an external pointer is garbage collected. However, I have some difficulties figuring out how to do that in an
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
Hi, I'm troubleshooting some native code on Windows that very occationally (and semi-randomly) crashes R. Already looked at "everything", I just want to double check that it is safe to UNPROTECT() allocated variables as soon as they are assigned to, say, a PROTECTed list. >From (R v2.3.0) Section 5.7.1 "Handling the effects of garbage collection" in "Writing R