search for: erroroccur

Displaying 17 results from an estimated 17 matches for "erroroccur".

Did you mean: erroccur
2009 Jan 08
1
Callbacks seems to get GCed.
...XP func) { PROTECT(callback2 = func); } R_CMethodDef cMethods[] = { {NULL} }; R_CallMethodDef callMethods[] = { {"set_callback1", (DL_FUNC) &set_callback1, 1}, {"set_callback2", (DL_FUNC) &set_callback2, 1}, {NULL} }; void r_trigger_callback1() { int errorOccurred; SEXP f = NULL; f = allocVector(LANGSXP, 1); SETCAR(f, callback1); PROTECT(f); R_tryEval(f, R_GlobalEnv, &errorOccurred); UNPROTECT(1); } void r_trigger_callback2() { int errorOccurred; SEXP f = NULL; f = allocVector(LANGSXP, 1); SETCAR(f, callback2); PROT...
2009 Aug 25
2
Clarifications please.
...e an R expression like Covariance <- round(cov(100 * SWX.RET), digits = 4) using lang, install and R_tryEval. 2) What exactly does install do? 3) I wrote the following code: #include <Rinternals.h> #include <Rembedded.h> int main (int argc, char** argv) { SEXP e,val; int errorOccurred; Rf_initEmbeddedR(argc, argv); // library("fPortfolio") PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // colMeans(SWX.RET) PROTECT(e = lang2(install("colMeans"),...
2007 Apr 06
2
wishlist: additional argument in R_tryEval (Rinternals.h)
Hi, R_tryEval, exported in Rinternals.h but not part of the API, is currently defined as: R_tryEval(SEXP e, SEXP env, int *ErrorOccurred); I'm trying to embed R in an application (basically yet another GUI), and this has been very helpful to catch errors. It would be even more helpful if it also gave access to the visibility flag. I can wrap this in a call to withVisible, and that works great, but if there is an error, trace...
2012 Apr 18
1
C - R integration: Memory Issues
...from source with shared libraries enabled and the compiler I use is gcc version 4.61 in a Ubuntu 11.10 linux machine. This is my function: static int prediction(double *berHistory, int berValues, double *ber) { SEXP e; SEXP bers; SEXP mean; int i; int errorOccurred; static int init = 0; char *argv[] = {"REmbeddedPostgres", "--gui=none", "--silent"}; int argc = sizeof(argv)/sizeof(argv[0]); // Initialize Embedded R if (init == 0) { Rf_initEmbeddedR(argc, argv); } init...
2004 Aug 18
3
R as shared library
...rce")); 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_source_fun,NULL,&errorOccurred); if (errorOccurred){ // Send a message to stderr (apache redirects this to the error log) fprintf(stderr,"apache2_mod_R: source(%s) failed!\n",r->filename); fflush(stderr); }...
2006 Jul 11
2
Converting SEXP to primitive C types
...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, &errorOccurred); printf("Returned: {%d}\n", VECTOR_ELT(val, 0) ); Where error.R is contains: foo <- function(x=3, y=6) { z <- x * y z } But the output is just "0", not the correct "18". Any ideas? Thanks for your help!
2011 Jan 26
2
Dealing with R list objects in C/C++
...R(arg)[2] = allocVector(REALSXP, 4); REAL(VECTOR_PTR(arg)[2])[0] = 10.0; REAL(VECTOR_PTR(arg)[2])[1] = 11.0; REAL(VECTOR_PTR(arg)[2])[2] = 12.0; REAL(VECTOR_PTR(arg)[2])[3] = 13.0; PROTECT(call = lang2(install(entryPoint.c_str()), arg)); ret = R_tryEval(call, R_GlobalEnv, &errorOccurred); I'll be grateful if you can point me to any online docs/samples. Thanks in advance, Wayne _______________________________________________ This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient o...
2009 Sep 16
2
I want to get a reference to this time series object
...ction on SWX.RET. So how do I get a reference to this object? #include <stdio.h> #include <R.h> #include <Rinternals.h> #include <Rdefines.h> #include <Rembedded.h> int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,portVal,tsAssets; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec o...
2016 Jul 07
1
Detecting user interrupts in R_tryEval
Is there any way to distinguish between an error and a user interruption in R_tryEval? In both cases the ErrorOccurred argument is set to 1. For my application I need a different action in case of a SIGINT. >From the source code I infer that R_tryEval basically wraps eval in R_ToplevelExec, which returns TRUE if fun returns normally, FALSE if it results in a jump to top level. However both an error and SIGIN...
2007 Apr 07
2
Rf_PrintValue problem with methods::show
...ion | head -1 R version 2.6.0 Under development (unstable) (2007-04-06 r41080) $ export LD_LIBRARY_PATH=`${RPROG} RHOME`/lib $ cat parseEvalS4.c #include <Rinternals.h> #include <Rembedded.h> #include <R_ext/Parse.h> int main(int argc, char *argv[]) { SEXP e, val; int i, errorOccurred; ParseStatus status; char *cmds[] = { "show(5)", "show(cbind2)", "cbind2" }; argv[0] = "R"; Rf_initEmbeddedR(argc, argv); for (i = 0; i < 3; i++) { printf("** I **: Executing command: %s\n", cmds[i]); PROT...
2014 May 02
1
backtrace while trying to clear workspace
...n protectedEval (d=<value optimized out>) at context.c:747 #23 0x00002aaaaaf87cfe in R_ToplevelExec (fun=0x2aaaaaf87370 <protectedEval>, data=0x7fffffffde00) at context.c:702 #24 0x00002aaaaaf87d89 in R_tryEval (e=<value optimized out>, env=<value optimized out>, ErrorOccurred=0x61) at context.c:761 #25 0x00002aaaaadeb109 in executeText ( prog=0x7fffffffe0a0 "*rm(list = ls(all = TRUE));*", Thanks [[alternative HTML version deleted]]
2009 Aug 25
1
R command line behaving funny
...the library function but still I get these errors. However, if I embed the R code into a C program like below it works. Why is this happening? I'm very confused. Program: #include <Rinternals.h> #include <Rembedded.h> int main (int argc, char** argv) { SEXP e,val; int errorOccurred; Rf_initEmbeddedR(argc, argv); PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); PROTECT(e = lang2(install("cov"), install("SWX.RET"))); val = (R_tryEval(e, NULL, &amp...
2007 May 01
1
Embedding R and registering routines
Hello, The use of .Call and the like all depend on loading shared libraries and registering routines from it. Also, .Primitive and .Internal depend on routines being registered in the R binary. And applications that embed R can override routines declared in Rinterfac.h, but is there a way for an application embedding R to register other routines defined in the application without loading a
2009 Sep 29
3
How do I access class slots from C?
...what I wrote so far: #include <stdio.h> #include <R.h> #include <Rinternals.h> #include <Rdefines.h> #include <Rembedded.h> int main(int argc, char** argv) { SEXP e,c,portSpec,portData,portConstr,portVal,portWeights,tsAssets,tsReturns,nAssets,reciprocal; int errorOccurred,nx,ny,i,j; double *v; const char *x,*y; Rf_initEmbeddedR(argc, argv); // loading fPortfolio PROTECT(e = lang2(install("library"), mkString("fPortfolio"))); R_tryEval(e, R_GlobalEnv, NULL); UNPROTECT(1); // creating a default portfolioSpec o...
2008 Jul 18
0
Rcpp from C++
...))), rho); return ans; } To get the data of an R-variable you should be able to use the constructors from Rcpp that take an SEXP as argument, but i also haven't tried that yet. What I found to be useful too is the routine for evaluating R-commands: //evaluating commands int errorOccurred; ParseStatus status; SEXP cmdSexp, cmdexpr, ans = R_NilValue; PROTECT(cmdSexp = Rf_allocVector(LANGSXP, 1)); char* cArr[4]; cArr[0] = "a <- seq(1,20)"; cArr[1] = "b <- seq(1,20)"; cArr[2] = "c <- a+ b"; cArr[3] = "prin...
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 Feb 04
5
simple example of C interface to R
i'd like to use the C interface to R in a program i'm writing. as a starting point, i'm trying to create a very simple C program that uses R. i've read the R documentation on this, but i'm having trouble figuring out where SEXP is defined and how to use it. i noticed someone else on this list also tried to use the C interface, but they ran into similar problems: