[Rd] _R_CHECK_DEPENDS_ONLY_ vs. packages in .Library [was: Check package without suggests]

2023-07-19 Thread Ivan Krylov
(Moving this one idea to R-devel)

В Wed, 19 Jul 2023 09:21:46 +0200
Henrik Bengtsson  пишет:

> If you're on macOS, and have installed R the default way, it takes
> more work to test on that platform. It works out of the box on Linux
> and MS Windows.  See the '[R-SIG-Mac] CRAN installer for macOS -
> directory permissions' thread started in April 2022
> ,
> continued in May 2022
> , and
> June 2022
> . It
> was then renamed to 'System-wide site library [Was: CRAN installer
> for macOS - directory permissions]' in June 2022
> .

Currently, a check with _R_CHECK_DEPENDS_ONLY_=TRUE assumes that
.Library only has base and recommended packages. This assumption can be
broken on macOS, and also on other operating systems when R is
installed into a writeable directory or is running without installation
(e.g. R-devel from an SVN checkout) and the user doesn't pre-create a
separate library.

What would be the downsides to implementing _R_CHECK_DEPENDS_ONLY_ the
same way that _R_CHECK_NO_RECOMMENDED_ is already implemented? The
latter works by creating fake packages (with a DESCRIPTION and an empty
file called "dummy_for_check" but nothing else in them) in a temporary
library that take precedence over the ones in .Library and fail loading.

-- 
Best regards,
Ivan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] proposal for WRE: clarify that use of S4 classes implies use of superclasses

2023-07-19 Thread Mikael Jagan

If a package has

importClassesFrom(P, C)

in its NAMESPACE, then should it _also_ have

importClassesFrom(P, )
importClassesFrom(Q, )
## and so on

... ?  I think that WRE could be more clear on this point, and in any case
I _think_ that the answer is yes.

Notably, I think that this rule would resolve some of the problems
with stale caches that I described in this thread from September:

https://stat.ethz.ch/pipermail/r-devel/2022-September/081971.html

I've attached a script demonstrating my point.  It creates and installs a
package named TestPackage with

importClassesFrom(Matrix, dgCMatrix, CsparseMatrix)

in NAMESPACE and

setClass("whatever", contains = "dgCMatrix")

in R/*.R.  After installing the package, I see:


> ns <- asNamespace("TestPackage")
> names(ns)
 [1] ".__C__generalMatrix"  ".__C__Matrix" ".__C__sparseMatrix"
 [4] ".__C__compMatrix" ".__C__whatever"   "zzz"
 [7] ".packageName" ".__C__dsparseMatrix"  ".__NAMESPACE__."
[10] ".__C__dMatrix"".__S3MethodsTable__."
> sort(names(ns))
 [1] ".__C__Matrix" ".__C__compMatrix" ".__C__dMatrix"
 [4] ".__C__dsparseMatrix"  ".__C__generalMatrix"  ".__C__sparseMatrix"
 [7] ".__C__whatever"   ".__NAMESPACE__."  ".__S3MethodsTable__."
[10] ".packageName" "zzz"
> sort(names(parent.env(ns)))
[1] ".__C__CsparseMatrix" ".__C__dgCMatrix" "setClass"


i.e., the imported classes are cached in the parent of the namespace (the
imports environment), and superclasses of dgCMatrix that are _not_ imported
are cached in the namespace itself.  The caching of superclasses does _not_
occur if I add all of the superclasses to the importClassesFrom directive
in NAMESPACE _or_ if I delete the call to setClass in R/*.R.

It is precisely these cached superclasses that are liable to become stale,
because, if I understand correctly, the namespace is populated and serialized
at _install_ time, whereas the imports environment is populated at _load_ time.

Hence by clarifying in WRE that packages should import exported superclasses
of classes that they extend, etc., we could stem some of the "staleness" on
CRAN ...

But maybe my analysis is mistaken, so I'll wait for comments from others ...

Mikaelpackage <- "TestPackage"
dir.create(file.path(package, "R"), recursive = TRUE)

cat(file = file.path(package, "DESCRIPTION"), "
Package: TestPackage
Version: 0.0-0
License: GPL (>= 2)
Description: A (one paragraph) description of what
  the package does and why it may be useful.
Title: My First Collection of Functions
Author: First Last [aut, cre]
Maintainer: First Last 
Imports: Matrix, methods
")

cat(file = file.path(package, "NAMESPACE"), "
export(zzz)
importFrom(methods, setClass)
importClassesFrom(Matrix, dgCMatrix, CsparseMatrix)
")

cat(file = file.path(package, "R", paste0(package, ".R")), "
zzz <- function() double(3L)
#setClass(\"whatever\", contains = \"dgCMatrix\")
")

tools:::Rcmd(c("build", package))
tools:::Rcmd(c("INSTALL", Sys.glob(paste0(package, "_*.tar.gz"

## unlink(Sys.glob(paste0(package, "*")), recursive = TRUE)
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel