[Rd] Package Building and Name Space

Martin Morgan mtmorgan at fhcrc.org
Thu Jan 24 14:47:00 CET 2008


Hi Joh --

I guess you have something like

f <- function() {}

MyPackage::f()

If you replace that with

f <- function() {}

.onLoad <- function(libname, pkgname) {
    MyPackage::f()
}

I think you'll be fine. The problem is, as the message says, at the
time of evaluation with your current scheme MyPackage is not on the
search path (has not yet been loaded); the message about no name space
is a bit spurious, since of course something that can not yet be found
cannot have a name space. From ?.onLoad, .onLoad finds the name space
even though the package is not on the search path.

Hope that helps,

Martin

Johannes Graumann <johannes_graumann at web.de> writes:

> On Wednesday 23 January 2008 18:24:15 Duncan Murdoch wrote:
>> On 1/23/2008 11:31 AM, Johannes Graumann wrote:
>> > On Wednesday 23 January 2008 17:25:38 Duncan Murdoch wrote:
>> >> On 1/23/2008 11:11 AM, Johannes Graumann wrote:
>> >> > ... sorry for reposting this in a more appropriate forum than
>> >> > r.general ...
>> >> >
>> >> > Hello,
>> >> >
>> >> > I just don't get this and would appreciate if someone could write a
>> >> > line or two: I'm trying to build this package and it stops installing
>> >> > after I add
>> >> >
>> >> > the following to the NAMESPACES file:
>> >> >>importFrom(gsubfn,strapply)
>> >> >
>> >> > The error during the package test is:
>> >> >
>> >> > Error in MyPackage::MyFunction :
>> >> >   package 'MyPackage' has no name space and is not on the search path
>> >> > Calls: <Anonymous> ... <Anonymous> -> switch -> sys.source -> eval ->
>> >> > eval -> ::
>> >> > Execution halted
>> >> >
>> >> > 'MyFunction' contains 'strapply' from gsubfn.
>> >> >
>> >> > Please tell me where I err.
>> >>
>> >> The file is called NAMESPACE, not NAMESPACES.
>> >
>> > And that's what it's called here ... sorry for the typo above. The error
>> > remains the same.
>>
>> With the obscuring you've done it's pretty hard to be sure, but I'd
>> assume you have the expression MyPackage::MyFunction somewhere in your
>> package, but MyPackage doesn't have a namespace.  In that case, you have
>> to make sure it is attached via
>>
>> library(MyPackage)
>>
>> or
>>
>> require(MyPackage)
>>
>> before you can use the "::" operator.
>
> But it's "mypackage" I'm trying to check ... can't attach that yet since I 
> need to package and install it first ...
>
> Joh
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793



More information about the R-devel mailing list