Excuse me if this is inappropriate content for this list, but I thought it might be the best place -- and the best audience -- to ask about a design decision for the R language. Programs or analyses written in R typically use library() to pull in functions from non-core packages. This differs markedly from most languages*, which usually offer some way to selectively import symbols. For example, in Python you'd see "from random import randint", and so on. Within R packages, the NAMESPACE file provides this exact functionality with the importFrom() directive, but the R language itself does not expose this as a function for regular users. I know that R did not have namespaces for some of its early existence, but I'm curious as to why the language never acquired an import() or importFrom() replacement for library() when it did get them. Was it purely for compatibility with S and earlier R versions? Or was there a principled difference of opinion on how R code should be written at stake? Any insight from those of you familiar with R's history would be deeply appreciated. Regards, Aaron ps. I am aware of the very clever "import" package, which provides exactly this feature -- I am more wondering why such an approach was never adopted by the language itself. * Most languages with real modules/namespaces, I mean. [[alternative HTML version deleted]]
Duncan Murdoch
2018-Jul-22 13:10 UTC
[Rd] R History: Why is there no importFrom() function?
On 21/07/2018 10:54 PM, Aaron Jacobs wrote:> Excuse me if this is inappropriate content for this list, but I thought it > might be the best place -- and the best audience -- to ask about a design > decision for the R language. > > Programs or analyses written in R typically use library() to pull in > functions from non-core packages. This differs markedly from most > languages*, which usually offer some way to selectively import symbols. For > example, in Python you'd see "from random import randint", and so on.I think there are two reasons. First, the :: operator is so convenient. If you really wanted "from random import randint" you could write randint <- random::randint but most people don't bother with the assignment, preferring to just work with random::randint in their code. The second reason is that R encourages complex programs to be written as packages, which do have the importFrom() directive. If you've got great big scripts where you would want to import certain functions and don't want the overhead of the package:: prefix, you're doing it wrong. Duncan Murdoch> > Within R packages, the NAMESPACE file provides this exact functionality > with the importFrom() directive, but the R language itself does not expose > this as a function for regular users. > > I know that R did not have namespaces for some of its early existence, but > I'm curious as to why the language never acquired an import() or > importFrom() replacement for library() when it did get them. Was it purely > for compatibility with S and earlier R versions? Or was there a principled > difference of opinion on how R code should be written at stake? > > Any insight from those of you familiar with R's history would be deeply > appreciated. > > Regards, > Aaron > > ps. I am aware of the very clever "import" package, which provides exactly > this feature -- I am more wondering why such an approach was never adopted > by the language itself. > > * Most languages with real modules/namespaces, I mean. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Michael Lawrence
2018-Jul-22 13:13 UTC
[Rd] R History: Why is there no importFrom() function?
I can't speak to the history per se, but I can give an opinion on the current situation. R is a programming language, as is Python, but R is also a system for interactive data analysis. Outside of the software/package context, library() is almost always sufficient. When it is not, consider "foo <- package::foo". While not as well structured as an importFrom() call, it does make the side effect explicit. When that becomes onerous, it is probably past time to transition to a package. Michael On Sat, Jul 21, 2018 at 7:54 PM, Aaron Jacobs <atheriel at gmail.com> wrote:> Excuse me if this is inappropriate content for this list, but I thought it > might be the best place -- and the best audience -- to ask about a design > decision for the R language. > > Programs or analyses written in R typically use library() to pull in > functions from non-core packages. This differs markedly from most > languages*, which usually offer some way to selectively import symbols. For > example, in Python you'd see "from random import randint", and so on. > > Within R packages, the NAMESPACE file provides this exact functionality > with the importFrom() directive, but the R language itself does not expose > this as a function for regular users. > > I know that R did not have namespaces for some of its early existence, but > I'm curious as to why the language never acquired an import() or > importFrom() replacement for library() when it did get them. Was it purely > for compatibility with S and earlier R versions? Or was there a principled > difference of opinion on how R code should be written at stake? > > Any insight from those of you familiar with R's history would be deeply > appreciated. > > Regards, > Aaron > > ps. I am aware of the very clever "import" package, which provides exactly > this feature -- I am more wondering why such an approach was never adopted > by the language itself. > > * Most languages with real modules/namespaces, I mean. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel