Re: [R] packagename:::functionname vs. importFrom
Thanks very much Luke for clarifying. Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3175567.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Thanks Luke. By the namespace from which you import is loaded when your package is I take it that you are saying that all such referenced packages are loaded up front, which is not what I hoped. And it's too bad you can't import unexported objects, as that rather defeats the purpose of importFrom. Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3174003.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Thanks Hadley, Luke, Martin, and Bill. Bill captured the essence of my reasons for needing an unexported function. Other reasons include occasional overrides of dispatching rules, and providing parallel versions of some functions that exist in other packages to make them easier to use in some sense. I could ask the package creator to export those functions but it would not make sense to him to do so. Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3174011.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
On Tue, 4 Jan 2011, Frank Harrell wrote: Thanks Luke. By the namespace from which you import is loaded when your package is I take it that you are saying that all such referenced packages are loaded up front, which is not what I hoped. That is what happens. You can use conditional imports in the NAMESPACE but that isn't appropriate for all setting. Using :: is reasonable if you want to use a fuction only if its package is available. Using ::: is code is a really bad idea for reasons already explained inthis thread. And it's too bad you can't import unexported objects, as that rather defeats the purpose of importFrom. The purpose of importFrom is to avoid a full import. So in no sense does this defeat the purpose of importFrom. Best, luke Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] packagename:::functionname vs. importFrom
In my rms package I use the packagename:::functionname construct in a number of places. If I instead use the importFrom declaration in the NAMESPACE file would that require the package to be available, and does it load the package when my package loads? If so I would keep using packagename::: to avoid up-front loading of other packages that are not always used. Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3172684.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Hi Frank, I think you mean packagename::functionname? The three colon form is for accessing non-exported objects. Otherwise, I think using :: vs importFrom is functionally identical - either approach delays package loading until necessary. Hadley On Mon, Jan 3, 2011 at 9:45 PM, Frank Harrell f.harr...@vanderbilt.edu wrote: In my rms package I use the packagename:::functionname construct in a number of places. If I instead use the importFrom declaration in the NAMESPACE file would that require the package to be available, and does it load the package when my package loads? If so I would keep using packagename::: to avoid up-front loading of other packages that are not always used. Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3172684.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
On Mon, Jan 3, 2011 at 3:48 PM, Hadley Wickham had...@rice.edu wrote: Hi Frank, I think you mean packagename::functionname? The three colon form is for accessing non-exported objects. Normally two colons suffice, but within a package you need three to access exported but un-imported objects :) Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
I think you mean packagename::functionname? The three colon form is for accessing non-exported objects. Normally two colons suffice, but within a package you need three to access exported but un-imported objects :) Are you sure? Note that it is typically a design mistake to use ‘:::’ in your code since the corresponding object has probably been kept internal for a good reason. Consider contacting the package maintainer if you feel the need to access the object for anything but mere inspection. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Well, I'm pretty sure that, inside package A, calling B::functionName will not work if B has not been imported. That's why I use ::: (after spending some time trying to figure out why :: didn't work). At least that was the state of affairs as of R 2.9 or so, perhaps things have changed since then. Peter On Mon, Jan 3, 2011 at 4:48 PM, Hadley Wickham had...@rice.edu wrote: I think you mean packagename::functionname? The three colon form is for accessing non-exported objects. Normally two colons suffice, but within a package you need three to access exported but un-imported objects :) Are you sure? Note that it is typically a design mistake to use ‘:::’ in your code since the corresponding object has probably been kept internal for a good reason. Consider contacting the package maintainer if you feel the need to access the object for anything but mere inspection. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Correct. I'm doing this because of non-exported functions in other packages, so I need ::: I'd still appreciate any insight about whether importFrom in NAMESPACE defers package loading so that if the package is not actually used (and is not installed) there will be no problem. Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/packagename-functionname-vs-importFrom-tp3172684p3172984.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
Correct. I'm doing this because of non-exported functions in other packages, so I need ::: But you really really shouldn't be doing that. Is there a reason that the package authors won't export the functions? I'd still appreciate any insight about whether importFrom in NAMESPACE defers package loading so that if the package is not actually used (and is not installed) there will be no problem. Imported packages need to be installed - but it's the import vs. suggests vs. depends statement in DESCRIPTION that controls this behaviour, not the namespace. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
If you use ::: to access non-exported functions, as Frank confesses he does, then you can't complain if in the next release of the package involved the non-exported objects are missing and things are being done another way entirely. That's the deal. On the other hand, sometimes package authors do not envisage all the ways their package will be used and neglecting to export some object is mostly because the author simply did not anticipate that anyone would ever need to use it. But sometimes they do. A common case is when you need to do some operations very efficiently and there are simplifications in the input of which you can take advantage to cut down on the overheads. In that case you usually need the cut-down (non-exported) workhorse rather than the (exported) show-pony front end. The documentation suggests that if you ever need to use ::: perhaps you should be contacting the package maintainer to have the article in question exported. This makes a lot of sense, but it can also creates quite a bit of work for the maintainers, too, if they agree to do it. It's a very grey area, in my experience. Bill Venables. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hadley Wickham Sent: Tuesday, 4 January 2011 3:06 PM To: Frank Harrell Cc: r-help@r-project.org Subject: Re: [R] packagename:::functionname vs. importFrom Correct. I'm doing this because of non-exported functions in other packages, so I need ::: But you really really shouldn't be doing that. Is there a reason that the package authors won't export the functions? I'd still appreciate any insight about whether importFrom in NAMESPACE defers package loading so that if the package is not actually used (and is not installed) there will be no problem. Imported packages need to be installed - but it's the import vs. suggests vs. depends statement in DESCRIPTION that controls this behaviour, not the namespace. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
On 01/03/2011 09:06 PM, Hadley Wickham wrote: Correct. I'm doing this because of non-exported functions in other packages, so I need ::: But you really really shouldn't be doing that. Is there a reason that the package authors won't export the functions? I'd still appreciate any insight about whether importFrom in NAMESPACE defers package loading so that if the package is not actually used (and is not installed) there will be no problem. I think that with importFrom(packagename, functioname), the package will fail to INSTALL with message object 'functioname' is not exported by namespace:packagename'. If the function is exported from packagname, then R CMD check will complain that 'Namespace dependency not required: packagename', which is to say that Imports: packagename is needed in the DESCRIPTION file. Packages that are listed in the Imports field of DESCRIPTION must be available at install time, so this implies that the user has packagename installed. I think this is trying to corral you to good programming practice: use Imports: packagename in the DESCRIPTION, use importsFrom(packagename, functioname) in the NAMESPACE, and only use functions that are exported from packagename. Martin Imported packages need to be installed - but it's the import vs. suggests vs. depends statement in DESCRIPTION that controls this behaviour, not the namespace. Hadley -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] packagename:::functionname vs. importFrom
On Mon, 3 Jan 2011, Frank Harrell wrote: Correct. I'm doing this because of non-exported functions in other packages, so I need ::: I'd still appreciate any insight about whether importFrom in NAMESPACE defers package loading so that if the package is not actually used (and is not installed) there will be no problem. It does not -- the namespace from which you import is loaded when your package is. (Also you can't import unexported variables.) Best, luke Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- Luke Tierney Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: l...@stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.