How can I load dependencies in an R package?

Viewed 2473

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

Imports: 
    dplyr,
    ggplot2,
    ncdf4

And I have an example function where I use the third dependency

testFun <- function(file, lat, long){
  ncfname <- file.path(file,fsep = .Platform$file.sep)
  xfile <- nc_open(ncfname) #Opens the NetCDF file
  lat <- ncvar_get(xfile, 'lat') #Extracts all latitudes

  ...Calculations

  return(XYZ)
}

When I Build and Reload the package, and I run the function, it could not find function "nc_open".

BUT, it works when I replace it with ncdf4::nc_open

Am I supposed to prefix packagename:: to every dependency I use in the code? or am I missing something?

Ordinarily, I would like all the dependencies to be installed from the DESCRIPTIONS and it's functions available for use without requiring the package prefix everytime.

2 Answers
Related