Re: [Rd] Questions about imports to a namespace

From: Duncan Murdoch <>
Date: Tue, 03 Jul 2012 06:41:45 -0400

On 12-07-02 10:53 PM, Simon Knapp wrote:
> Hi,
> I am a bit unsure about using imports in packages and have a few
> questions. I'm sure the answer to some of these is 'it depends', but
> I'm interested in what others think and 'best practices' when this is
> the case.
> 1) If I use an import or importFrom declaration in a NAMESPACE, should
> I also qualify the package in calls to the imported function (e.g.
> maptools::readShapePoly)?

No, you won't need that. I would expect it to slow things down a bit, since it needs two searches instead of one: look up "maptools", look up "readShapePoly".

> 2) If the 'best practice' is to qualify the calls, when does one stop;
> e.g. is it good/bad to say base::sapply?
> 3) If one is calling a (S3) generic, should one qualify the namespace?
> Can this cause problems?

I think it wouldn't hurt other than the slight speed hit.

> 4) Is it better to check for arguments that are missing, or use a
> default value of, say, NA; i.e. is missing(arg) preferable to

That depends. It's easier to set an argument to a special value in a call from another function than it is to conditionally set it to be missing, but there are only a couple of general purpose choices for "missing" values: NA and NULL, and you might want a user to be able to specify those. (You can also use negative values for counts, etc., in particular contexts.)

> 5) I would like to declare a (S3) generic 'cleanup(x)' but
> 'cleanup(...)' already exists in R.utils, which my package depends on.
> Should I do it?

No. Use a different name. If you are using R.utils, your users are also using it, and their code may want to call R.utils::cleanup without the R.utils:: prefix.

> 6) I am used to writing 'requires(package)' for each package I use
> within a function. If I have used import or importFrom in my
> NAMESPACE, should I still do this?

No, it just slows things down, and can cause other problems for users because it changes the search list.

Duncan Murdoch mailing list Received on Tue 03 Jul 2012 - 10:44:49 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 Jul 2012 - 08:50:31 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive