tmPlot在名称空间中,但未找到其依赖项 [英] tmPlot is in namespace, but its dependencies are not found

查看:258
本文介绍了tmPlot在名称空间中,但未找到其依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用treemap中的tmPlot函数的软件包,但是当我尝试使用该函数时,它抛出一个错误,指出没有加载其依赖项之一:

I have a package which uses the tmPlot function from treemap, but when I try to use the function, it throws an error that one of its dependencies isn't loaded:

Error in tmPlot(data, index = index, vSize = vSize) : 
  could not find function "brewer.pal"

依赖性已安装并位于名称空间中.

The dependency is installed and in the namespace.

这个问题有一点点设置,是一个包装问题,但是我尝试将其最小化:

This question has a little bit of setup, being a package problem, but I've tried to make it as minimal as possible:

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

Ensure you have treemap (and all its dependencies) installed.

我已经建立了一个名为"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被列为treemap的依赖项,因此应该自动导入,不是吗?

You should get the error I described right at the beginning. Why does this happen? RColorBrewer is listed as Depends for treemap, so it should be be automatically imported, should it not?

推荐答案

问题确实出在树形图上. treemap使用brewer.palImports: RColorBrewerimportFrom(RColorBrewer, brewer.pal)也应该使用.

The problem is really with treemap. treemap uses brewer.pal, and so should Imports: RColorBrewer and importFrom(RColorBrewer, brewer.pal).

按现在的样子,如果用户说library(treemap),treemap和RColorBrewer附加到search()路径,并且在评估tmPlot时在搜索路径上找到brewer.pal,一切都会好的.当然,如果用户说brewer.pal="yeast"之类的东西,包装会破裂,因为会发现错误的符号.这是使用名称空间来保护树图的功能不受用户可能影响的原因之一.

As it stands now, everything is ok if the user says library(treemap), treemap and RColorBrewer are attached to the search() path, and when tmPlot is evaluated brewer.pal is found on the search path. Of course the package would break if the user were to say brewer.pal="yeast" or something, because the wrong symbol would be found; this is one of the reasons for a name space, to protect treemap's functions from what the user might do.

但是,当您(正确)导入树形图时会发生什么?树图已加载(到内存中),但树图及其依赖项均未附加(到搜索路径).因此未找到brewer.pal.

But what happens when you (correctly) Imports: treemap? treemap is loaded (into memory) but neither treemap nor its dependencies are attached (to the search path). So brewer.pal is not found.

如果树形图要用于Imports:RColorBrewer,则在通过调用library(treemap)将树形图附加到搜索路径时,以及仅将树形图导入到程序包中时,都可以找到brewer.pal.

If treemap were to Imports: RColorBrewer, then brewer.pal would be found both when treemap were attached to the search path by a call to library(treemap), and when only imported into your package.

与树形图的维护者联系,并要求他们在构建其名称空间时做得更加仔细.

Contact the maintainer of treemap and ask them to do a more careful job of constructing their name space.

这篇关于tmPlot在名称空间中,但未找到其依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆