tmPlot is in namespace, but its dependencies are not found

亡梦爱人 提交于 2019-11-30 20:48:00

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

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.

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.

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.

before calling the tmPlot(data, index = index, vSize = vSize), you need to load RColorBrewer:

require(RColorBrewer)

I think it's due to the fact that you use Imports instead of Depends in your DESCRIPTION file.

If you use Depends: treemap, the treemap package is loaded and attached when you load your package, and as such the treemap dependencies are loaded too.

If you use Imports: treemap, then only the specified namespace is imported, ie you can use the treemap variables in your functions. But it seems that in this case the treemap dependencies are not loaded.

So I think you should either use Depends: treemap (but it seems that the use of Imports is promoted these days), or import RColorBrewer directly from your package.

Sorry, not sure this really answers your question, and you may be already perfectly aware of all of these points...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!