From murdoch@dunc@n @ending from gm@il@com  Sun Jul 22 15:10:05 2018
From: murdoch@dunc@n @ending from gm@il@com (Duncan Murdoch)
Date: Sun, 22 Jul 2018 09:10:05 -0400
Subject: [Rd] R History: Why is there no importFrom() function?
In-Reply-To: <CAPncpof0FyXBh+p=SjGHPtcpQi=mS+TSZ+c0pWVMuak6Vy3oaQ@mail.gmail.com>
References: <CAPncpof0FyXBh+p=SjGHPtcpQi=mS+TSZ+c0pWVMuak6Vy3oaQ@mail.gmail.com>
Message-ID: <2b263bd8-c2d8-e56f-4314-fd3f2773021d@gmail.com>

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
>



[Rd] R History: Why is there no importFrom() function?
Duncan Murdoch