Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

namespaces - R: Error in as.environment(pos) / Error during wrapup: no item called "package:[package]" on the search list

This is similar to this but with a followup question:

I'm preparing my package for submission to CRAN. In one script, it gives the titular error:

Error in as.environment(pos): no item called "package:shapefiles" on the search list

or

Error during wrapup: no item called "package:shapefiles" on the search list

If, like the similar thread linked above, I add

attachNamespace("shapefiles")

Then I no longer get that error, but instead I sometimes get the error or warning:

namespace(shapefiles) was already taken

I believe this happens if the function/script is run more than once. What's so weird about this to me is that

#' @import shapefiles

is in that script's markdown block,

Which means

import(shapefiles)

is in NAMESPACE, and

Imports:
    shapefiles (>= 0.7),

is in DESCRIPTION. I have numerous other package dependencies which are imported the same way (correctly, I believe), and none of them produce this error. I don't see why this is behaving differently therefore, and would like to avoid having either issue before submitting to CRAN. The code that calls this package, in my script, is

shapefiles::read.shapefile(savename)

Script is here, for reference.

Thanks in advance for any ideas!

Edit: steps to reproduce:

setwd("/folder")
library(devtools)
install_github("SimonDedman/gbm.auto")
library(gbm.auto)
gbm.basemap(bounds = c(-81.7, -80.3, 24.7, 25.9),
            savedir = "/folder")

I've just removed shapefiles:: from the code. The correct output is produced regardless.

question from:https://stackoverflow.com/questions/65875341/r-error-in-as-environmentpos-error-during-wrapup-no-item-called-package

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Problem resolved itself after commenting out attachNamespace("shapefiles"). No idea why.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...