How can I load dependencies in an R package?

前端 未结 2 1889
鱼传尺愫
鱼传尺愫 2020-12-11 22:38

I am developing an R package where this is available in the DESCRIPTIONS file

Imports: 
    dplyr,
    ggplot2,
    ncdf4

And

相关标签:
2条回答
  • 2020-12-11 23:22

    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.

    0 讨论(0)
  • 2020-12-11 23:30

    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.

    0 讨论(0)
提交回复
热议问题