Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaces in R packages

Tags:

r

How do people learn about giving an R package a namespace? I find the documention in "R Extensions" fine, but I don't really get what is happening when a variable is imported or exported - I need a dummy's guide to these directives.

How do you decide what is exported? Is it just everything that really shouldn't required the pkg:::var syntax? What about imports?

Do imports make it easier to ensure that your use of other package functions doesn't get confused when function names overlap?

Are there special considerations for S4 classes?

Packages that I'm familiar with that use namespaces such as sp and rgdal are quite complicated - are there simple examples that could make things clearer?

like image 972
mdsumner Avatar asked Dec 06 '10 21:12

mdsumner


People also ask

What are r dependencies?

A dependency is a code that your package needs to run. Dependencies are managed by two files. The DESCRIPTION manages dependencies at the package level; i.e. what packages needs to be installed for your package to work. R has a rich set of ways to describe different types of dependencies.

What is roxygen2?

roxygen2 dynamically inspects the objects that it's documenting, so it can automatically add data that you'd otherwise have to write by hand. It abstracts over the differences in documenting S3 and S4 methods, generics and classes, so you need to learn fewer details.


2 Answers

I have a start on an answer on the devtools wiki: http://adv-r.had.co.nz/Namespaces.html

like image 146
hadley Avatar answered Sep 30 '22 12:09

hadley


Few years later here....

I consolidated findings from Chambers, other StackOverflow posts, and lots of tinkering in R: http://blog.obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/

This is less about implementing NAMESPACE/IMPORTS/DEPENDS and more about the purpose of these structures. Answers some of your questions.

like image 45
SFun28 Avatar answered Sep 30 '22 12:09

SFun28