How can I load dependencies in an R package?

半腔热情 提交于 2019-11-28 14:27:11

Either:

  • explicitly prefix the function with the package it's from: ncdf4::nc_open(...)

Or:

  • add a line in your NAMESPACE file importFrom(ncdf4, nc_open) and then in your code, call the function without the package: nc_open(...)

Rather than adding an importFrom line for every function you want to import, you can also use import(ncdf4) to snarf everything from that package.

The easiest way and most correct way is to directly pull your function from the package without opening any packages which might obliterate someone's current environment.

Try this:

xfile <- ncdf4::nc_open(ncfname)

It should access what you need without conflicts. That is the current preferred method because it leaves things as it found them for your users. It also makes it easy for people to KNOW what is happening should they go exploring.

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