Skip to content

data/ R files can assume utils is attached, but load_all() fails #324

@MichaelChirico

Description

@MichaelChirico

Forked from r-lib/roxygen2#1736 as I traced the issue to {pkgload}.


data() itself attaches {utils}:

https://github.com/r-devel/r-svn/blob/519293fba5c71f4bd3594f22b8548b5d4f8806b2/src/library/utils/R/data.R#L160-L161

This is as documented, per ?data:

data ensures that the utils package is attached, in case it had been run via utils::data.

Minimal reprex:

tree UtilsDataPkg
# UtilsDataPkg/
# ├── data
# │   └── ut_data.R
# ├── DESCRIPTION
# └── man

# 3 directories, 2 files

# DESCRIPTION:
Package: UtilsDataPkg
Title: UtilsDataPkg
Version: 0.1
RoxygenNote: 7.3.3
Encoding: UTF-8

# data/ut_data.R
myData = read.csv(text = "a,b,c\n1,2,3\n")

Results in:

pkgload::load_all()
# ℹ Loading UtilsDataPkg
# Error in read.csv(text = "a,b,c\n1,2,3\n") : 
#   could not find function "read.csv"

But R CMD INSTALL UtilsDataPackage works, as does loading the data set without {utils}:

$ R CMD INSTALL .
$ R_DEFAULT_PACKAGES=NULL R --vanilla
utils::data(ut_data, package='UtilsDataPkg')
ls()
# [1] "myData"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions