Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R package: how to make my package loading other package when I library my package

I have made my own package called "test" and I install it. However, there exist some problem.

For example, in my .R file, I use function "rowQuantiles" from other package called "matrixStats".

And I already add

import(matrixStats)

to namespace file

and add

Imports:matrixStats (>= 0.57.0)

to description file.

However, whenever I library my own pakcage

library(test)

The following error always comes out

could not find function "rowQuantiles"

How can I make that whenever I library my own package it will load other required packages. Just like the following

> library(ggpubr)
Loading required package: ggplot2
like image 717
Nicolas H Avatar asked Oct 28 '25 04:10

Nicolas H


1 Answers

Key to understand this is to understand the difference between loading a package and attaching a package.

Packages listed under Imports: are only loaded when your package attached, i.e. when you do library(mypkg). In contrast, packages listed under Depends: are loaded and attached. So, if you use:

Depends: matrixStats

then all of matrixStats functions will be on the search() path when you package is attached.

like image 65
HenrikB Avatar answered Oct 29 '25 18:10

HenrikB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!