0

I am creating my own package in R. Within my package I am using the ggnet2 function from GGally package. I am trying to get my package CRAN ready and Im using a bunch of tests from the devtools package.

My issue is, I get an error when I run the following devtools tests:

library(devtools)

check_win_release()
check_win_devel() 

The error that is being thrown back is:

Error: please install the package 'network'.  install.packages('network') 
  Backtrace:
      x
   1. \-myPackage::plotNetwork(vi) test_plots.R:34:2
   2.   +-base::suppressMessages(...)
   3.   | \-base::withCallingHandlers(...)
   4.   \-GGally::ggnet2(...)
   5.     \-GGally:::require_namespaces(c("network", "sna", "scales"))

Now, when I look up the source code for ggnet2, the very 1st line of code is:

 require_namespaces(c("network", "sna", "scales"))

In my NAMESPACE file I have the ggnet2 function imported, along with ggplot2, like so:

import(ggplot2)
importFrom(GGally,ggnet2)

And I also have GGally and ggplot2 under the Imports field in my DESCRIPTION file within my package.

I have tried adding network and sna to the suggests field in my DESCRIPTION file, but the error still remains (I am using the scales package elsewhere within my package, so Im importing it separately).

This error is from a test file that I'm using with devtools::test() but (on my machine I have these packages installed) I'm guessing that when I run check_win_release() the machine that the tests are being preformed on don't have the required packages!?

I was wondering how do I solve this error? Or what are the best practices when importing a function that requires the namespace from other functions from other packages?

Electrino
  • 2,636
  • 3
  • 18
  • 40
  • I think `network` is a package installed with the base version of R. So you probably don't need to add it to the list. But that is just a guess. – van Nijnatten Mar 28 '21 at 17:52
  • I don't believe `network` is installed with base R. IT has it's own CRAN release and I had to install the `network` package when I wanted to use it on my machine – Electrino Mar 28 '21 at 17:55
  • You can probably recreate the problem using the package `renv`. See https://rstudio.github.io/renv/articles/renv.html . It can create an empty environment for development and then you can test the build, tests and installation. – van Nijnatten Mar 28 '21 at 18:00
  • Have you tried putting `network`, `GGally` and `sna` in the Imports field on your `DESCRIPTION` file? I suggest you use `usethis::use_package` to add them manual to your `DESCRIPTION` file, in that way there is no need for them to be included in your roxygen2 documentations. – Anoushiravan R Mar 28 '21 at 21:38
  • I was trying to avoid adding `network` and `sna` them to the imports field. I was trying to keep the number of imported packages to a minimum. – Electrino Mar 28 '21 at 22:01

0 Answers0