Skip to content

a problem sourcing a file using chdir=TRUE

3 messages · Luca Scrucca, Brian Ripley

#
There was a pre-existing bug.  ?source in 2.0.1 says

     file: a connection or a character string giving the name of the
           file or URL to read from.

yet it contained

     if (chdir && (path <- dirname(file)) != ".") {

You cannot reasonably run dirname() on a connection or a URL, and it 
throws an error in those cases.

We need a more elaborate detection mechanism, and some re-ordering of the 
code.
On Mon, 16 May 2005, Luca Scrucca wrote:

            

  
    
#
Dear R-users,

I used to give commands such as:
but with the latest v. 2.1.0 it does not seem to work anymore.
I tried to figure out what it was going on and it seems that the string
for which
[1] "character"
is changed to
[1] "file"       "connection"
when the connection is open by
file <- file(file, "r", encoding = encoding)

But this force the following if statement
if (chdir && is.character(file) && (path <- dirname(file)) != ".")
   { owd <- getwd()
     on.exit(setwd(owd))
     setwd(path)
   }
to be FALSE and then non changing of current directory is done.
Is this the desired behavior or some bug fix is required?

Luca

+-----------------------------------------------------------------------+
| Dr. Luca Scrucca                                                      |
| Dipartimento di Economia, Finanza e Statistica                        |
| Sezione di Statistica                          tel. +39-075-5855226   |
| Universit?? degli Studi di Perugia              fax. +39-075-5855950   |
| Via Pascoli - C.P. 1315 Succ. 1                                       |
| 06100 PERUGIA  (ITALY)                                                |
|                                                  (o_   (o_   (o_      |
| E-mail:   luca at stat.unipg.it                    //\   //\   //\       |
| Web page: http://www.stat.unipg.it/luca         V_/_  V_/_  V_/_      |
+-----------------------------------------------------------------------+
#
This and some related problems should be fixed in tomorrow's R-patched 
snapshot.
On Mon, 16 May 2005, Luca Scrucca wrote: