0

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?

lucacerone
  • 9,859
  • 13
  • 52
  • 80
  • What do you mean by "in the code for my package ... library(methylumi)" ? Do you have the proper imports in your `NAMESPACE` file? Have you read the `R-exts` tutorial file? – Carl Witthoft Feb 24 '14 at 12:36
  • Hi Carl, I did read the R-exts tutorial, but I have to admit not everything is crystal clear to me. Say I have my main file "mypackage.r" in the R folder, what I did is adding library(methylumi) at the top of the file. I generate NAMESPACE using roxygen2 (but there are no lines for methyulimi), also in my DESCRIPTION file I have added a Depends statement for methylumi. – lucacerone Feb 24 '14 at 12:50
  • I'm no expert in `NAMESPACE` either, but have a look at the files for the package `Rmpfr` for some example code. HTH :-) – Carl Witthoft Feb 24 '14 at 12:59
  • 3
    You need to add an @import directive in "mypackage.R" (you don't need `library`). `roxygen2` will set up the NAMESPACE for you. You will still need to add the import entry in DESCRIPTION. See this **[SO question](http://stackoverflow.com/questions/8597993/does-roxygen2-automatically-write-namespace-directives-for-imports-packages)**. Also, consider using import over depends, as import only makes the package available within your package as per this **[other SO Q/A](http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends)**. – BrodieG Feb 24 '14 at 13:22

2 Answers2

3

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

vermouth
  • 301
  • 2
  • 12
2

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