Displaying 20 results from an estimated 62 matches for "cfunction".
Did you mean:
function
2012 Mar 17
1
how to pass 'raw' values with cfunction()?
I am having trouble handing "raw" data to a C function, using "cfunction", as demonstrated in the function and output pasted below. Can anyone suggest what I'm doing incorrectly? Thanks. Dan Kelley [Dalhousie University].
1. TEST FILE
library(inline)
code <- 'Rprintf("inside f(), b is 0X%x\\n", *b);'
f <- cfunction(sig=signature(b=...
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 = PROTECT(ScalarLogical(0));
setAttrib(success, install("foo"), mkString("bar"));
UNPROTECT(1);
return success;
')
However after running test2(), then test1() will...
2013 Feb 01
1
Problem using raw vectors with inline cfunction
Hello,
>From what I understood from the documentation I found, when using the
inline cfunction with convention=".C",
R raw vectors should be given as unsigned char* to the C function.
But consider the following script:
library(inline)
testRaw <- cfunction(signature(raw='raw', len='integer')
, body='
int l = *len;
int i = 0;
Rpri...
2012 Nov 30
3
segfault debugging
Hello everybody,
I have written a script with two inline cfunctions. The script crashes from time to time with:
? ?*** caught segfault ***
? address 0x10, cause 'memory not mapped'
The crashs happen within R code after the cfunctions were executed. Nevertheless I think
that the pointers in my cfunctions are not used correctly.
I tried to find some exampl...
2019 Sep 15
2
REprintf could be caught by tryCatch(message)
...s catch(message("a"))?
Regards,
Jan Gorecki
catch = function(expr) {
tryCatch(expr,
message=function(m) cat("caught message\n"),
warning=function(w) cat("caught warning\n"),
error=function(e) cat("caught error\n")
)
}
library(inline)
Cstop = cfunction(c(), 'error("%s\\n","a"); return R_NilValue;')
Cwarning = cfunction(c(), 'warning("%s\\n","a"); return R_NilValue;')
Cmessage = cfunction(c(), 'REprintf("%s\\n","a"); return R_NilValue;')
catch(stop("a"))...
2019 Sep 15
2
[External] REprintf could be caught by tryCatch(message)
...pr) {
> > tryCatch(expr,
> > message=function(m) cat("caught message\n"),
> > warning=function(w) cat("caught warning\n"),
> > error=function(e) cat("caught error\n")
> > )
> > }
> > library(inline)
> > Cstop = cfunction(c(), 'error("%s\\n","a"); return R_NilValue;')
> > Cwarning = cfunction(c(), 'warning("%s\\n","a"); return R_NilValue;')
> > Cmessage = cfunction(c(), 'REprintf("%s\\n","a"); return R_NilValue;')
> &g...
2020 Jun 30
2
Build a R call at C level
Hi All,
I was reading the R extension manual section 5.11 ( Evaluating R expression
from C) and I tried to build a simple call to the sum function. Please see
below.
call_to_sum <- inline::cfunction(
language = "C",
sig = c(x = "SEXP"), body = "
SEXP e = PROTECT(lang2(install(\"sum\"), x));
SEXP ans = PROTECT(eval(e, R_GlobalEnv));
UNPROTECT(2);
return ans;
")
call_to_sum(1:3)
The above works. My question is how do I add the argument "na.rm=...
2020 Jun 30
3
Build a R call at C level
...oved...
Please see "5.11 Evaluating R expressions from C" from "Writing R
Extensions"
Best
Tomas
> Still R-package-devel mailing list should be preferred for this kind
> of questions.
> Not sure if that is the best way, but works.
>
> call_to_sum <- inline::cfunction(
> language = "C",
> sig = c(x = "SEXP"), body = "
>
> SEXP e = PROTECT(lang2(install(\"sum\"), x));
> SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
> SETCDR(CDR(e), r_true);
> SET_TAG(CDDR(e), install(\"na.rm\"));...
2010 Apr 13
3
Inline Package: void vs return type functions
...et say a double[][] or a user define
class)
2) I am working with an extensive library built by someone else and I don't
have the time/knowledge to change it by means of working with "pointer"
variables in order to avoid the return sentence,,,
question A: can I use the -inline- "cfunction" without resorting to the Rcpp
functionality?
-- if this is true, question A2: do I need to go deep in the source code
coming from the library (that I am trying to use) to perform the interface
through the Rcpp classes?
questionB: is it true that the working with the -inline- function you have...
1998 Nov 26
1
Saving memory usage -- .C(....., DUP = FALSE) danger?
Just found out [R 0.63, standard -v -n] :
> rm(list=ls())
> gc()
free total
Ncells 96538 200000
Vcells 214008 250000
> hist(runif(50000))
Error: heap memory (1953 Kb) exhausted [needed 390 Kb more]
which is a bit astonishing given that I still have room for 214000 double's
> u1 <- runif(50000)
> u2 <- runif(50000)
> gc()
2019 Sep 15
0
[External] REprintf could be caught by tryCatch(message)
...an Gorecki
>
> catch = function(expr) {
> tryCatch(expr,
> message=function(m) cat("caught message\n"),
> warning=function(w) cat("caught warning\n"),
> error=function(e) cat("caught error\n")
> )
> }
> library(inline)
> Cstop = cfunction(c(), 'error("%s\\n","a"); return R_NilValue;')
> Cwarning = cfunction(c(), 'warning("%s\\n","a"); return R_NilValue;')
> Cmessage = cfunction(c(), 'REprintf("%s\\n","a"); return R_NilValue;')
>
> catch(s...
2009 Dec 22
0
Rcpp 0.7.0: R/C++ integration now even easier
...eed);
for (int i=0; i<len; i++) {
v[i] = gsl_rng_get (r);
}
gsl_rng_free(r);
return RcppSexp(v).asSexp();
'
## turn into a function that R can call
## compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
funx <- cfunction(signature(s="numeric", n="numeric"),
gslrng,
includes="#include <gsl/gsl_rng.h>",
Rcpp=TRUE,
cppargs="-I/usr/include",
libargs="-lgsl -lgs...
2009 Dec 22
0
Rcpp 0.7.0: R/C++ integration now even easier
...eed);
for (int i=0; i<len; i++) {
v[i] = gsl_rng_get (r);
}
gsl_rng_free(r);
return RcppSexp(v).asSexp();
'
## turn into a function that R can call
## compileargs redundant on Debian/Ubuntu as gsl headers are found anyway
funx <- cfunction(signature(s="numeric", n="numeric"),
gslrng,
includes="#include <gsl/gsl_rng.h>",
Rcpp=TRUE,
cppargs="-I/usr/include",
libargs="-lgsl -lgs...
2019 Sep 16
0
[External] REprintf could be caught by tryCatch(message)
...atch(expr,
>>> message=function(m) cat("caught message\n"),
>>> warning=function(w) cat("caught warning\n"),
>>> error=function(e) cat("caught error\n")
>>> )
>>> }
>>> library(inline)
>>> Cstop = cfunction(c(), 'error("%s\\n","a"); return R_NilValue;')
>>> Cwarning = cfunction(c(), 'warning("%s\\n","a"); return R_NilValue;')
>>> Cmessage = cfunction(c(), 'REprintf("%s\\n","a"); return R_NilValue;')
&...
2010 Apr 08
2
I can´t run the example shown in the inline package
I want to run some R script using the inline package (which allows to create
and run inline C++ code in my humble understanding).
So, after loading the required packages and copy and paste the example that
runs C code (in the Reference Manual as a PDF), I have a compilation error.
Any body has ever tried this inline package?
--
View this message in context:
2015 Jun 01
2
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
...benchmarking
disagree. It looks like there is a big overhead keeping track of the
sum `s` being NA, which is supported by the fact that summing over 'z'
is costs half of 'y'.
Now, I *cannot* reproduce the above using the following 'inline' example:
> sum2 <- inline::cfunction(sig=c(x="double", narm="logical"), body='
double *x_ = REAL(x);
int narm_ = asLogical(narm);
int n = length(x);
double sum = 0;
for (R_xlen_t i = 0; i < n; i++) {
if (!narm_ || !ISNAN(x_[i])) sum += x_[i];
}
return ScalarReal(sum);
')
> x <- rep(0, 1e...
2019 Jan 05
1
unsorted - suggestion for performance improvement and ALTREP support for POSIXct
...vement for a vectors of double of moving REAL() outside the for loop.
# example as implemented in isUnsorted
body = "
R_xlen_t n, i;
n = XLENGTH(x);
for(i = 0; i+1 < n ; i++)
if(REAL(x)[i] > REAL(x)[i+1])
return ScalarLogical(TRUE);
return ScalarLogical(FALSE);";
f1 = inline::cfunction(sig = signature(x='numeric'), body=body)
# example updated with only one call to REAL()
body = "
R_xlen_t n, i;
n = XLENGTH(x);
double* real_x = REAL(x);
for(i = 0; i+1 < n ; i++)
if(real_x[i] > real_x[i+1])
return ScalarLogical(TRUE);
return ScalarLogical(FALSE);";
f2...
2017 Apr 14
2
potential bug in attribute handling for externalptr
Is the following expected behavior?
> mkext <- inline::cfunction(language="C", body='return
R_MakeExternalPtr(NULL, install("tag"), R_NilValue);')
> x <- mkext()
> y <- x
> attr(y, "foo") <- "bar"
> attributes(x)
$foo
[1] "bar"
I would expect that modifying y's attributes sh...
2020 Jun 30
0
Build a R call at C level
It is quite known that R documentation on R C api could be improved...
Still R-package-devel mailing list should be preferred for this kind
of questions.
Not sure if that is the best way, but works.
call_to_sum <- inline::cfunction(
language = "C",
sig = c(x = "SEXP"), body = "
SEXP e = PROTECT(lang2(install(\"sum\"), x));
SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
SETCDR(CDR(e), r_true);
SET_TAG(CDDR(e), install(\"na.rm\"));
Rf_PrintValue(e);
SEXP ans = PROTEC...
2020 Jun 30
0
Build a R call at C level
...ressions from C" from "Writing R
> Extensions"
>
> Best
> Tomas
>
> > Still R-package-devel mailing list should be preferred for this kind
> > of questions.
> > Not sure if that is the best way, but works.
> >
> > call_to_sum <- inline::cfunction(
> > language = "C",
> > sig = c(x = "SEXP"), body = "
> >
> > SEXP e = PROTECT(lang2(install(\"sum\"), x));
> > SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
> > SETCDR(CDR(e), r_true);
> > SET_TAG(CDDR...