Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import one function in R package (without importFrom)

Tags:

r

r-package

I'm writing an R package and I'd like to use one function from another package (plotKML). This external package has so many dependencies that I don't want my users to be required to download etc. If I use importFrom(plotKML, readGPX) in the NAMESPACE file it will load all of plotKML into the namespace and download all dependencies which I don't want.

So the question is: is it appropriate to copy the code for the one function I need (ensuring that all the dependencies in that one function are included)? If so what is appropriate for the attribution/documentation -- do I copy the documentation from the original?

There is a great discussion of this issue in this post and the answer by Brian Diggs is very helpful. But he ends with "For your example, you may be better off copying the code for memisc::describe into your package, although that approach has its own problems and caveats" so I'm left with some uncertainty about what the problems are and whether it's appropriate from a attribution perspective.

like image 324
ZRoss Avatar asked Jun 16 '15 14:06

ZRoss


People also ask

What does imports mean in r package?

Imports is used for packages that are needed by your package but that don't need to be loaded with library() . Packages referred to in @import or @importFrom statements in your Roxygen2 comments, or whose functions are accessed via the :: operator, should be here.

Which R function is used to load a package?

packages() , which as you can expect, installs a given package. library() which loads packages, i.e. attaches them to the search list on your R workspace.

How do you create a package in R?

Open a new project in RStudio. Go to the 'File' menu and click on 'New Project. ' Then select 'New Directory,' and 'R Package' to create a new R package.


1 Answers

Questions about the appropriate attribution would probably be best resolved by contacting the package author directly. As noted in the comments above, that package appears to use GPL-3, which should mean that you can include the function in your package but your package must then also be GPL-3 licensed. (As always, probably no one here is a lawyer so that's on you to check...)

The primary downside to copying just the function you need is that then you are responsible for maintaining it. This probably also means maintaining it in a way that keeps it in sync with the original version from plotKML. Depending on the package, surrounding code and how often it is updated that could be fairly simple or it could be horrible.

like image 111
joran Avatar answered Sep 18 '22 01:09

joran