Displaying 20 results from an estimated 26 matches for "definevar".
2007 Mar 27
3
Use of 'defineVar' and 'install' in .Call
...we will find the root
guesses: interval for the solution
stol: tolerance
rho: environment
The original functions I use are:
SEXP mkans(double x) {
SEXP ans;
PROTECT(ans = allocVector(REALSXP, 1));
REAL(ans)[0] = x;
UNPROTECT(1);
return ans;
}
double feval(double x, SEXP f, SEXP rho) {
defineVar(install("x"), mkans(x), rho);
return(REAL(eval(f, rho))[0]);
}
SEXP zero(SEXP f, SEXP guesses, SEXP stol, SEXP rho) {
double x0 = REAL(guesses)[0], x1 = REAL(guesses)[1], tol = REAL(stol)[0];
double f0, f1, fc, xc;
if(tol <= 0.0) error("non-positive tol value");
f0...
2007 Mar 27
3
Use of 'defineVar' and 'install' in .Call
...we will find the root
guesses: interval for the solution
stol: tolerance
rho: environment
The original functions I use are:
SEXP mkans(double x) {
SEXP ans;
PROTECT(ans = allocVector(REALSXP, 1));
REAL(ans)[0] = x;
UNPROTECT(1);
return ans;
}
double feval(double x, SEXP f, SEXP rho) {
defineVar(install("x"), mkans(x), rho);
return(REAL(eval(f, rho))[0]);
}
SEXP zero(SEXP f, SEXP guesses, SEXP stol, SEXP rho) {
double x0 = REAL(guesses)[0], x1 = REAL(guesses)[1], tol = REAL(stol)[0];
double f0, f1, fc, xc;
if(tol <= 0.0) error("non-positive tol value");
f0...
2008 Jan 16
1
Pb with defineVar() example in the "Writing R Extensions" manual
..."Writing R Extensions" manual
is really safe:
SEXP mkans(double x)
{
SEXP ans;
PROTECT(ans = allocVector(REALSXP, 1));
REAL(ans)[0] = x;
UNPROTECT(1);
return ans;
}
double feval(double x, SEXP f, SEXP rho)
{
defineVar(install("x"), mkans(x), rho);
return(REAL(eval(f, rho))[0]);
}
In C, the order in which function arguments are evaluated before the
function itself is called is undefined. Hence there is no guarantee
that install("x") will be evaluated before mkans(x). What happen...
2001 Apr 24
2
assigning objects from .C/.Call
Hi,
In section 4.6.7 of "Writing R Extensions" (Version 1.2.1, 2001-01-15)
the C function defineVar() is described as "... the equivalent
of assign(symbol, value, envir = rho, inherits = FALSE) ..."
I interpreted the above (wrongly) as meaning that defineVar() makes
a copy of its "value" argument into the object whose name is specified
in "symbol" in the "r...
2008 Jan 04
1
Evaluating R expressions from C
...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));
for(i = 0; i < n; i++) {
defineVar(install("x"), VECTOR_ELT(list, i), rho);
SET_VECTOR_ELT(ans, i, eval(expr, rho));
}
I'm trying to understand this code beyond just copying it, and don't find
definitions for many of the calls. PROTECT and SEXP have been well discussed
previously in the docu...
2003 May 28
0
R_GlobalEnv
...s the current R global environment from
within C, using R_GlobalEnv.
In the example below, Rgui (R 1.7.0. Win2K) crashes when I try
to run assignValueToFooInR_GlobalEnv, but not when I run
assignValueToFooInRhoEnv with Rho=.GlobalEnv. Can anyone tell me why?
[ My motivation is that I want use defineVar to initialise a
workingEnvironment (corresponding to Value below), so that event-handler
functions for a specific C library (which must have a specific
prototype) can call R functions by looking up workingEnvironment with
findVar. Earlier, I tried a static global SEXP variable in C to
keep tra...
2014 Mar 05
1
[PATCH] Code coverage support proof of concept
...v_freqs_hash for filename */
+static void cov_store_new_line(const char* filename, int line) {
+ SEXP lines, lines2;
+ int len, i, *t1, *t2;
+
+ lines = findVarInFrame(R_Cov_freqs_hash, install(filename));
+ if (lines == R_UnboundValue) { /* new file */
+ lines = cov_new_lines_vector(line + 1);
+ defineVar(install(filename), lines, R_Cov_freqs_hash);
+ }
+ if (length(lines) <= line) {
+ /* lines vector too short */
+ PROTECT(lines2 = cov_new_lines_vector(line + 1)); /* should allocate (line+1)*growth_rate */
+ len = length(lines);
+ i = 0;
+ t1 = INTEGER(lines);
+ t2 = INTEGER(lines2);
+ fo...
2010 Feb 20
1
how to create a SEXP which could be accessed in embedded R
Hi all,
I am not familiar with writing R extensions. In a C program, I want to create a SEXP and access it in embedded R. How to let the embedded engine know there's a new vector? For example, after creating a SEXP, parsing 'ls()' in embedded R and then evaluating, STRSXP returned will contain the name of the SEXP. Any help would be appreciated.
Regards,
Spiral
[[alternative HTML
2005 Sep 18
0
Updated rawConnection() patch
...{
Routtextconn this = (Routtextconn)con->private;
- SEXP tmp;
- int idx = ConnIndex(con);
+ SEXP tmp, rm;
if(strlen(this->lastline) > 0) {
- PROTECT(tmp = lengthgets(this->data, ++this->len));
- SET_STRING_ELT(tmp, this->len - 1, mkChar(this->lastline));
- defineVar(this->namesymbol, tmp, VECTOR_ELT(OutTextData, idx));
- this->data = tmp;
+ PROTECT(tmp = lengthgets(this->data, this->len+1));
+ SET_STRING_ELT(tmp, this->len, mkChar(this->lastline));
+ } else {
+ PROTECT(tmp = lengthgets(this->data, this->len));
+ }
+ /* remove c...
1998 Jan 03
1
R-beta: NextMethod(.Generic) bug
I'm a day-old R newbie (but a war-weary S veteran), with couple of
first-day questions:
In R 0.61, this code fails.
Ops.test <- function(e1,e2)
{
e1 <- NextMethod(.Generic)
e1
}
x <- 4
class(x) <- "test"
y <- x < 3
The error message is "Error in NextMethod(.Generic) : negative length vectors
are not allowed.".
I assume it is a bug.
2005 Nov 07
3
R thread safe
..._init_lock(&lck);
#pragma omp parallel for default(none) private(i, alocal) shared(list,
lck,rho, ans, n, expr)
for(i = 0; i < n; i++) {
omp_set_lock(&lck);
PROTECT(alocal = allocVector(VECSXP, 1));
alocal = allocVector(VECSXP, 1);
defineVar(install("x"), VECTOR_ELT(list, 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_un...
1998 Sep 22
1
"Segmentation Fault - core dumped" in R 0.62.3
I am occasional getting "Segmentation Fault - core dumped" in R 0.62.3 (I think
more often then I did in 0.62.2). I have not been able to do this in any
reliably reproducible way yet, but thought I would mention the problem in case
some else can isolate it.
Paul Gilbert
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read
2005 Aug 22
2
RFC: "loop connections"
...ms,
+ Rconnection con)
+{
+ Routloopconn this = (Routloopconn)con->private;
+ SEXP tmp;
+ int idx = ConnIndex(con);
+
+ PROTECT(tmp = lengthgets(this->data, this->len + size*nitems));
+ memcpy(RAW(tmp)+this->len, ptr, size*nitems);
+ this->len += size*nitems;
+ defineVar(this->namesymbol, tmp, VECTOR_ELT(OutTextData, idx));
+ this->data = tmp;
+ UNPROTECT(1);
+ return nitems;
+}
+
+static void outloop_init(Rconnection con, char *mode, int idx)
{
- Routtextconn this = (Routtextconn)con->private;
+ Routloopconn this = (Routloopconn)con->pr...
2009 Aug 06
1
[R] Repeatable, But Time Varying R GUI Crash (PR#13880)
On 8/6/2009 4:11 PM, Marilyn & Rich Short wrote:
> Hello,
>
> I'm having a problem in R. The R GUI is crashing with a message to
> contact Microsoft for the solution. I've contacted Microsoft and they
> are of no help. Below is a distilled set of code that will cause the
> crash. As you will see, there are two do-loops within which is a "load"
>
2003 Jan 13
1
Evaluating expressions from within C code
Dear R experts!
I want to evaluate expressions from within C code. For instance,
I want this code:
/* ============ -- C code -- ============== */
#include <R.h>
#include <Rinternals.h>
SEXP foo(SEXP expr, SEXP rho)
{
SEXP x;
PROTECT(x = allocVector(REALSXP, 1));
REAL(x)[0] = 1;
UNPROTECT(1);
return
2007 Aug 16
0
call R function in c++ program
...CT( vector_SEXP = allocVector(REALSXP, std_vector.size()) );
int i = 0;
for(std_iterator s_it=std_vector.begin(); s_it!=std_vector.end();
s_it++)
{
REAL(vector_SEXP)[i] = (double) *s_it;
i++;
}
UNPROTECT(1);
// for create a variable in R environement
defineVar(install("variable_name"), variable_value_SEXP, rho);
// for execute "complex" function (with parser)
PROTECT( e1 = mkString("plot(variable_name, type=\"l\")") );
PROTECT( e2 = R_ParseVector(e1, 1, &status, R_NilValue) );
R_tryEval(VECTOR_E...
2008 Jul 18
0
Rcpp from C++
...uot;
#include <R_ext/Parse.h>
#include <Rinternals.h>
#include <Rdefines.h>
//assigning a vector
SEXP ab;
PROTECT(ab = allocVector(REALSXP, 2));
REAL(ab)[0] = 123.45;
REAL(ab)[1] = 67.89;
UNPROTECT(1);
the attach a R variable name to the data using
void defineVar(SEXP symbol, SEXP value, SEXP rho)
void setVar(SEXP symbol, SEXP value, SEXP rho)
but I haven't tried that yet in detail.
getVar is the other way around and finds the data to an R variable name:
SEXP getVar(SEXP name, SEXP rho)
{
SEXP ans;
if(!isString(name) || length(name) != 1...
2009 Oct 01
2
creating environments in package's C code
Dear developers,
is it possible to create environments in C code of packages?
Simply using
SEXP env;
PROTECT (env = allocSExp(ENVSXP));
and assigning the enclosing environment with SET_ENCLOS seems to be
insufficient.
Best wishes,
Martin
--
Dr. Martin Becker
Statistics and Econometrics
Saarland University
Campus C3 1, Room 206
66123 Saarbruecken
Germany
2007 Sep 20
1
copying promise
1. Is there some way to copy a promise so that the copy has the same
expression in its promise as the original. In the following we
y is a promise that we want to copy to z. We
want z to be a promise based on the expression x since y is a
promise based on the expression x. Thus the answer to the code
below is desired to be z=2 but its 1, 1 and y in the next three
examples so they are not the
2019 Jul 13
2
Mitigating Stalls Caused by Call Deparse on Error
...hould not happen) */
??? ?if (traceback && inError < 2 && inError == oldInError) {
??? ???? inError = 2;
-?? ???? PROTECT(s = R_GetTraceback(0));
+?? ???? PROTECT(s = R_GetTracebackParsed(0));
??? ???? SET_SYMVALUE(install(".Traceback"), s);
??? ???? /* should have been defineVar
??? ??????? setVar(install(".Traceback"), s, R_GlobalEnv); */
@@ -1440,9 +1440,11 @@
??? ?PrintWarnings();
???? }
?}
-
+/*
+ * Return the traceback without deparsing the calls
+ */
?attribute_hidden
-SEXP R_GetTraceback(int skip)
+SEXP R_GetTracebackParsed(int skip)
?{
???? int nback = 0,...