Re: [R] can I call user-created functions without source() ?

From: Duncan Murdoch <>
Date: Tue 20 Jun 2006 - 00:41:17 EST

On 6/19/2006 10:19 AM, Joerg van den Hoff wrote:

> Duncan Murdoch wrote:

>> Just a few comments below on alternative ways to do the same things:
>> On 6/19/2006 8:19 AM, Joerg van den Hoff wrote:
>>> for short term usage of some specialized functions I have added some 
>>> lines to the `.Rprofile' in my home(!) directory as follows (probably 
>>> there are smarter solutions, but at least it works):
>>> #source some temporary useful functions:
>>> fl <- dir(path='~/rfiles/current',patt='.*\\.R$',full.names=TRUE)
>>> for (i in fl) {cat(paste('source("',i,'")\n',sep="")); source(i)}
>>> rm(i,fl)

>> Another way to do this without worrying about overwriting some existing
>> variables is
>> local({
>> fl <- ...
>> for (i in fl) ...
>> })

>> No need to remove fl and i at the end; they were created in a temporary
>> environment, which was deleted at the end.
> sure, that's better (just one more case, where I did'nt know of the 
> existence of a certain function). but what is the difference (with 
> regards to scope) of `i' or `fl' and the functions defined via sourcing? 
> are'nt both objects defined within `local'? why _are_ the functions 
> visible in the workspace? probably I again don't understand the 
> `eval'/environment intricacies.

Whoops, sorry. Yes, you'd need to be careful to assign them into globalenv(). Those ...'s weren't so simple.

Duncan Murdoch mailing list PLEASE do read the posting guide! Received on Tue Jun 20 01:13:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 20 Jun 2006 - 04:11:42 EST.

Mailing list information is available at Please read the posting guide before posting to the list.