[R] a problem sourcing a file using chdir=TRUE

Luca Scrucca luca at stat.unipg.it
Mon May 16 22:42:14 CEST 2005


Dear R-users,

I used to give commands such as:

> source(file="~/path/to/file.R", chdir=TRUE)

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
> class(file)
[1] "character"
is changed to
> class(file)
[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_/_      |
+-----------------------------------------------------------------------+




More information about the R-help mailing list