Skip to content
Prev 366953 / 398506 Next

Function that works within a package and not when copied in global environment. Why?

1. No they're not. e.g.
[1] FALSE
function ()
 - attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 6 1 20 6 20 1 1
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile'
<environment: 0x1026578d0>
function ()
 - attr(*, "srcref")=Class 'srcref'  atomic [1:8] 1 6 1 19 6 19 1 1
  .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile'
<environment: 0x102613028>
[1] TRUE

identical() is very fussy about whether t=2 objects are the same; they
must be identical in all respects, including attributes, classes, etc.
attached to them. The namespace object has different attributes
attached to it than the one you created.

2. You need to review how namespaces work. From the "Writing R
extensions" manual:

"The namespace controls the search strategy for variables used by
**functions in the package**. If not found locally, R searches the
package namespace first, then the imports, then the base namespace and
then the normal search path."

So if vectorize.args() is among the package functions, it will be
found by package functions but not by those you write unless
specifically qualified by :: or ::: depending on whether it is
exported.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Feb 2, 2017 at 6:30 AM, Marc Girondot via R-help
<r-help at r-project.org> wrote: