[Rcpp-commits] r3587 - in pkg/Rcpp: R inst/unitTests/testRcppClass/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 28 18:54:02 CEST 2012


Author: jmc
Date: 2012-04-28 18:54:01 +0200 (Sat, 28 Apr 2012)
New Revision: 3587

Modified:
   pkg/Rcpp/R/RcppClass.R
   pkg/Rcpp/inst/unitTests/testRcppClass/R/load.R
Log:
Use the globalVariables() in 2.15.1 to declare C++ fields & methods.
Checks the existence of globalVariables, so still seems to work for 2.15.0


Modified: pkg/Rcpp/R/RcppClass.R
===================================================================
--- pkg/Rcpp/R/RcppClass.R	2012-04-22 20:35:24 UTC (rev 3586)
+++ pkg/Rcpp/R/RcppClass.R	2012-04-28 16:54:01 UTC (rev 3587)
@@ -44,7 +44,7 @@
                          saveAs = Class,
                          where = topenv(parent.frame()),
                          ...) {
-    
+
     if(isBotchedSession()) {
         value <- setRefClass(Class, fields = fields, methods = methods,  contains = contains, where = where, ...)  # kludge -- see loadModule.R
         if(is.character(saveAs) && length(saveAs) == 1)
@@ -72,6 +72,12 @@
     value <- setRefClass(Class, fields = allfields,
                          contains = c(contains, "RcppClass"),
                          methods = allmethods, where=where, ...)
+    ## declare the fields and methods to shut up codetools
+    ## the R level fields and methods were declared by setRefClass
+    ## but we declare them again; globalVariables() applies unique()
+    if(exists("globalVariables", envir = asNamespace("utils"))) # >=2.15.1
+       utils::globalVariables(c(names(allfields), names(allmethods)),
+                              where)
     if(is.character(saveAs) && length(saveAs) == 1)
         assign(saveAs, value, envir = where)
     value

Modified: pkg/Rcpp/inst/unitTests/testRcppClass/R/load.R
===================================================================
--- pkg/Rcpp/inst/unitTests/testRcppClass/R/load.R	2012-04-22 20:35:24 UTC (rev 3586)
+++ pkg/Rcpp/inst/unitTests/testRcppClass/R/load.R	2012-04-28 16:54:01 UTC (rev 3587)
@@ -7,7 +7,7 @@
 
 ## some methods that use C++ methods
 evalqOnLoad({
-    library(methods)
+    ##library(methods)
      stdNumeric$methods(
     getEl = function(i) {
         i <- as.integer(i)
@@ -36,6 +36,7 @@
     )
 })
 
+
 ## loadModule("NumEx")
 
 ## loading the module should have defined the C++ class



More information about the Rcpp-commits mailing list