tmPlot在命名空间中,但找不到它的依赖项

前端之家收集整理的这篇文章主要介绍了tmPlot在命名空间中,但找不到它的依赖项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个使用treemap中的tmPlot函数的包,但是当我尝试使用该函数时,它会抛出一个错误,其中没有加载其中一个依赖项:
Error in tmPlot(data,index = index,vSize = vSize) : 
  could not find function "brewer.pal"

依赖项已安装在命名空间中.

这个问题有一些设置,是一个包问题,但我试图尽可能减少它:

确保安装了treemap(及其所有依赖项).

我做了一个名为’anRpackage’的目录.里面是一个文件夹(‘R’)和一个带有以下文字的DESCRIPTION文件

Package: anRpackage
Title: What the package does (short line)
Version: 1.0
Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
Imports:
    treemap
Collate:
    'maketree.R'

R /文件夹里面是一个名为’maketree.R’的R文件.其内容是:

#' maketree
#' 
#' @importFrom treemap tmPlot
#' @export maketree

maketree <-
function(data,index,vSize){
  tmPlot(data,index=index,vSize=vSize)
}

假设您位于’anRpackage’上方的目录中,请运行以下脚本:

library(roxygen2)
roxygenise("anRpackage/")

library(devtools)

build("anRpackage")
install("anRpackage")

重新启动R(最好使用–vanilla)并运行以下命令:

library(anRpackage)

data(mtcars)
maketree(mtcars,"cyl","mpg")

你应该在开始时得到我描述的错误.为什么会这样? RColorBrewer列为树形图的Depends,因此应该自动导入,如果不是?

问题实际上是树形图. treemap使用brewer.pal,因此应该导入:RColorBrewer和importFrom(RColorBrewer,brewer.pal).

现在看来,如果用户说库(树图),树图和RColorBrewer附加到search()路径,并且当评估tmPlot时,在搜索路径上找到brewer.pal,则一切正常.当然,如果用户说brewer.pal =“酵母”或其他东西,那么包装会破裂,因为会找到错误的符号;这是名称空间的原因之一,用于保护树形图的功能不受用户可能执行的操作.

但是当你(正确地)进口时会发生什么:树形图? treemap被加载(到内存中)但是树形图及其依赖项都没有附加(到搜索路径).所以找不到brewer.pal.

如果树图是Imports:RColorBrewer,那么当树图通过调用库(treemap)附加到搜索路径时,以及仅导入到包中时,都会找到brewer.pal.

联系treemap的维护者,让他们更仔细地构建他们的名字空间.

原文链接:https://www.f2er.com/javaschema/281339.html

猜你在找的设计模式相关文章