Hi,
I am using Rcpp in a package and I need to get a non exported function
in some other namespace.
I do something like the following but it seems to work only for exported
functions (or I guess any R variables):
Environment ns = Environment("package:stats");
Function fun = ns[".asSparse"];
This throws an error: "cannot convert to function".
I am running:
- R-2.13.0 on Ubuntu 10.04
- Rcpp 0.9.5
Actually, I would like to access any type of non-exported R variable,
but I imagine it would work the same and changing the left-side class
should do the trick.
I am sure there is an easy way to do this in Rcpp. Any suggestion?
Thank you.
Bests,
Renaud
[Rcpp-devel] Rcpp: accessing non exported function in a given namespace
4 messages · Romain Francois, Renaud Gaujoux, Dirk Eddelbuettel
5 days later
Le 22/07/11 16:10, Renaud a ?crit :
Hi,
I am using Rcpp in a package and I need to get a non exported function
in some other namespace.
I do something like the following but it seems to work only for exported
functions (or I guess any R variables):
Environment ns = Environment("package:stats");
Function fun = ns[".asSparse"];
This throws an error: "cannot convert to function".
I am running:
- R-2.13.0 on Ubuntu 10.04
- Rcpp 0.9.5
Actually, I would like to access any type of non-exported R variable,
but I imagine it would work the same and changing the left-side class
should do the trick.
I am sure there is an easy way to do this in Rcpp. Any suggestion?
Thank you.
Bests,
Renaud
Yes. You need Environment::namespace_env to get the namespace and not
the package environment.
Something like this:
fx <- cxxfunction( , '
Environment ns = Environment::namespace_env( "stats" ) ;
return ns[".asSparse"] ;
', plugin = "Rcpp" )
fx()
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/lJoWbH : Montpellier Com?die Club - Juin 2011 |- http://bit.ly/kaSV6U : Stand up set at Up The Creek `- http://bit.ly/hdKhCy : Rcpp article in JSS
Great. I knew it had to be possible... and as easy as this. Thank you. Renaud
On 28/07/2011 15:15, Romain Francois wrote:
Le 22/07/11 16:10, Renaud a ?crit :
Hi,
I am using Rcpp in a package and I need to get a non exported function
in some other namespace.
I do something like the following but it seems to work only for exported
functions (or I guess any R variables):
Environment ns = Environment("package:stats");
Function fun = ns[".asSparse"];
This throws an error: "cannot convert to function".
I am running:
- R-2.13.0 on Ubuntu 10.04
- Rcpp 0.9.5
Actually, I would like to access any type of non-exported R variable,
but I imagine it would work the same and changing the left-side class
should do the trick.
I am sure there is an easy way to do this in Rcpp. Any suggestion?
Thank you.
Bests,
Renaud
Yes. You need Environment::namespace_env to get the namespace and not
the package environment.
Something like this:
fx <- cxxfunction( , '
Environment ns = Environment::namespace_env( "stats" ) ;
return ns[".asSparse"] ;
', plugin = "Rcpp" )
fx()
Romain
On 28 July 2011 at 15:18, Renaud wrote:
| Great. | I knew it had to be possible... and as easy as this. Nice trick indeed. I just added it as a unit test so that I can look it up another time :) Dirk | Thank you. | | Renaud |
| On 28/07/2011 15:15, Romain Francois wrote:
| > Le 22/07/11 16:10, Renaud a ?crit :
| >> Hi,
| >>
| >> I am using Rcpp in a package and I need to get a non exported function
| >> in some other namespace.
| >> I do something like the following but it seems to work only for exported
| >> functions (or I guess any R variables):
| >>
| >> Environment ns = Environment("package:stats");
| >> Function fun = ns[".asSparse"];
| >>
| >> This throws an error: "cannot convert to function".
| >> I am running:
| >> - R-2.13.0 on Ubuntu 10.04
| >> - Rcpp 0.9.5
| >>
| >> Actually, I would like to access any type of non-exported R variable,
| >> but I imagine it would work the same and changing the left-side class
| >> should do the trick.
| >>
| >> I am sure there is an easy way to do this in Rcpp. Any suggestion?
| >> Thank you.
| >>
| >> Bests,
| >> Renaud
| >
| > Yes. You need Environment::namespace_env to get the namespace and not
| > the package environment.
| >
| > Something like this:
| >
| > fx <- cxxfunction( , '
| > Environment ns = Environment::namespace_env( "stats" ) ;
| > return ns[".asSparse"] ;
| > ', plugin = "Rcpp" )
| > fx()
| >
| > Romain
| >
| >
| >
|
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Gauss once played himself in a zero-sum game and won $50.
-- #11 at http://www.gaussfacts.com