From kirill.mueller at ivt.baug.ethz.ch  Tue Feb 11 02:53:22 2014
From: kirill.mueller at ivt.baug.ethz.ch (=?ISO-8859-1?Q?Kirill_M=FCller?=)
Date: Tue, 11 Feb 2014 02:53:22 +0100
Subject: [Rd] $new cannot be accessed when running from Rscript and methods
 package is not loaded
Message-ID: <52F98292.2090209@ivt.baug.ethz.ch>

Hi


Accesses the $new method for a class defined in a package fails if the 
methods package is not loaded. I have created a test package with the 
following single code file:

newTest <- function() {
   cl <- get("someClass")
   cl$new
}

someClass <- setRefClass("someClass")

(This is similar to code actually used in the testthat package.)

If methods is not loaded, executing the newTest function fails in the 
following scenarios:

- Package "depends" on methods (scenario "depend")
- Package "imports" methods and imports either the setRefClass function 
(scenario "import-setRefClass") or the whole package (scenario 
"import-methods")

It succeeds if the newTest function calls require(methods) (scenario 
"require").

The script at 
https://raw2.github.com/krlmlr/methodsTest/master/test-all.sh creates an 
empty user library in subdirectory r-lib of the current directory, 
installs devtools, and tests the four scenarios by repeatedly installing 
the corresponding version of the package and trying to execute newTest() 
from Rscript. I have attached the output. The package itself is on 
GitHub: https://github.com/krlmlr/methodsTest , there is a branch for 
each scenario.

Why does it seem to be necessary to load the methods package here?


Best regards

Kirill



[Rd] $new cannot be accessed when running from Rscript and methods package is not loaded
=?ISO-8859-1?Q?Kirill_M=FCller?=