search for: cmdexpr

Displaying 7 results from an estimated 7 matches for "cmdexpr".

2008 Aug 04
2
Parsing code with newlines
Dear List, When I try to parse code containing newline characters with R_ParseVector, I get a compilation error. How can I compile code that includes comments and newlines? I am using the following: void* my_compile(char *code) { SEXP cmdSexp, cmdExpr = R_NilValue; ParseStatus status; PROTECT (cmdSexp = allocVector (STRSXP, 1)); SET_STRING_ELT (cmdSexp, 0, mkChar (code)); PROTECT (cmdExpr = R_ParseVector (cmdSexp,-1,&status, R_NilValue)); UNPROTECT_PTR (cmdSexp); if (status != PARSE_OK) { return (voi...
2012 Feb 01
3
Crash in R using embedded.
.../R"); const char *R_argv[]= {"RInterfaceTest", "--gui=none", "--no-save", "--no-readline", "--silent"}; Rf_initialize_R(sizeof(R_argv)/sizeof(R_argv[0]), const_cast<char **>(R_argv)); setup_Rmainloop(); ParseStatus status; SEXP cmdSexp, cmdexpr = R_NilValue; int error; string rcommand = "f<-file(paste(tempdir(), \"/Routput.txt\", sep = \"\"), open=\"wt+\")\nsink(f)\n"; PROTECT(cmdSexp = allocVector(STRSXP, 1)); SET_STRING_ELT(cmdSexp, 0, mkChar(rcommand.c_str())); cmdexpr = PROTECT(R_ParseVector...
2013 Oct 16
1
Parallel R expression evaluations
...ndVar' is not an environment I am using the following code snippet for initializing R, parsing and evaluation of R expression // For initialization int res= Rf_initEmbeddedR(R_argc, (char**)R_argv); // For parsing and evaluation SEXP cmd1= Rf_mkChar(rscript); SEXP cmdSexp, cmdexpr, sresult = R_NilValue; ParseStatus status; R_len_t i=0; PROTECT(cmdSexp = Rf_allocVector(STRSXP, 1)); SET_STRING_ELT(cmdSexp, 0, cmd1); // parsing vector for R expressions cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue)); if (status != PARSE_OK) { UNPROTECT(2); //...
2009 Jan 08
1
Callbacks seems to get GCed.
...v, &errorOccurred); UNPROTECT(1); } void r_trigger_callback2() { int errorOccurred; SEXP f = NULL; f = allocVector(LANGSXP, 1); SETCAR(f, callback2); PROTECT(f); R_tryEval(f, R_GlobalEnv, &errorOccurred); UNPROTECT(1); } void r_exec(char *code) { SEXP cmdSexp, cmdExpr = R_NilValue; ParseStatus status; int i,errorOccurred; SEXP e; PROTECT (cmdSexp = allocVector (STRSXP, 1)); SET_STRING_ELT (cmdSexp, 0, mkChar (code)); PROTECT (cmdExpr = R_ParseVector (cmdSexp,-1,&status,R_NilValue)); UNPROTECT_PTR (cmdSexp); if (status == PARSE_OK)...
2009 Sep 03
1
Running an expression 1MN times using embedded R
..._ELT( mess , 0)); // fwrite(&SET_STATUS,sizeof(uint8_t),1,stderr); // uint32_t stle = strlen(status); // uint32_t len_rev = reverseUInt(stle); // fwrite(&len_rev,sizeof(uint32_t),1,stderr); // fwrite(status,stle,1,stderr); } SEXP rexpress(const char* cmd) { SEXP cmdSexp, cmdexpr, ans = R_NilValue; int i,Rerr; ParseStatus status; PROTECT(cmdSexp = Rf_allocVector(STRSXP, 1)); SET_STRING_ELT(cmdSexp, 0, Rf_mkChar(cmd)); cmdexpr = PROTECT(R_ParseVector(cmdSexp, -1, &status, R_NilValue)); if (status != PARSE_OK) { UNPROTECT(2); return(R_NilValue)...
2008 Jul 18
0
Rcpp from C++
...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] = "print(c)"; for (int CommandInd = 0; CommandInd&lt...
2008 Sep 03
8
suggestion of new API function for embedded programming.
While doing some embedded programming and trying to figure out how to generate a hand coded SEXP equivalent of the line "t.test(x,conf.level=(1-p))$conf.int[2]" I had an idea for an addition to the embedded API. There are a number of hidden or static parse functions (R_ParseBuffer, R_Parse1Buffer, etc.) which take an IoBuffer* and returns a parsed tree. If one or more of these