[Rcpp-devel] Using spatstat in Rcpp
Romain François
romain at r-enthusiasts.com
Wed Jun 11 19:13:29 CEST 2014
Hello,
You seem to be confusing R namespaces and C++ namespaces and assuming you can call an R function as if it belonged to a C++ namespace.
R functions and c++ functions are different things.
You can do something like:
// get the spatstat environment
Environment spatstat( "package:spatstat" ) ;
// get the discpartarea function from that env
Function discpartarea = spatstat["discpartarea"];
Then you can call discpartarea.
Romain
Le 11 juin 2014 à 19:01, mohammad ghorbani <ghorbani_ms at yahoo.com> a écrit :
> Hi there,
>
> I would like to call discpartarea() and as.owin() functions of spatstat from Rcpp. In a simple example
> consider the following C++ code in which I'm trying to access the above functions:
>
> #include <Rcpp.h>
> using namespace Rcpp;
>
> // [[Rcpp::export]]
> NumericVector IndepSelfCortCpp( NumericMatrix obsu) {
> NumericMatrix obsxy = obsu( _ , Range(1,2) ) ;
> NumericVector xyW= NumericVector::create(0,56,0,38);
> double rslt = 0;
>
> rslt= spatstat::discpartarea(obsxy, 0.1, spatstat::as.owin(xyW));
>
> return (rslt);
> }
> /* ** R
> obsu <- matrix(c(0.5, 1.5, 4, 12, 1,2,3,4,2,3,5,7), ncol=3)
> IndepSelfCortCpp(obsu)
> */
>
> When I source the file in Rstudio with sourceCpp(), I get the error:
> " 'spatstat' has not been declard "
>
> I was wondering, a direct call a function of an R package like spatstat is possible from Rcpp.
> If yes, Could anyone help me on debugging the code?
>
> Best Regards,
> Mohammad Ghorbani
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140611/58c482f9/attachment-0001.html>
More information about the Rcpp-devel
mailing list