Skip to content

data/ does not allow assuming utils is attached #1736

@MichaelChirico

Description

@MichaelChirico

However, 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:

roxygen2::roxygenize()
# ℹ 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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions