Make third party library available in my R package

2019-03-04 10:41发布

I am developing an R package that uses third party functions available in the Bioconductor package "methyilumi"

In the code for my R package at the very beginning I import methylumi with library(methylumi).

During the development (I use roxygen2 and devtools) everything works fine. However, when I install the package and run my functions, I get the error: could not find function "methylumIDAT".

Of course everything is solved if I import the package manually, but how can I make so that methylumi is available whenever I load my own package?

2条回答
Rolldiameter
2楼-- · 2019-03-04 11:18

This is done with the NAMESPACE file and also noted in the DESCRIPTION file. There are a few ways to import a function in NAMESPACE, but the simplest is just importFrom("[PACKAGE_NAME]",[FUNCTION_NAME). Then, in DESCRIPTION, add the package name to imports.

See this very good tutorial from Friedrich Leisch.

http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf

查看更多
We Are One
3楼-- · 2019-03-04 11:38

Since you are using devtools, you can add

devtools::use_package("methyilumi")

in the console, and call methyilumi::methylumIDAT in the body of your function. That way, the package is automatically listed in Imports in the DESCRIPTION file.

This sections gives the instructions for several different cases: http://r-pkgs.had.co.nz/namespace.html#imports

查看更多
登录 后发表回答