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

From: Luca Scrucca <luca_at_stat.unipg.it>
Date: Tue 17 May 2005 - 06:42:14 EST


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@stat.unipg.it //\ //\ //\ |
| Web page: http://www.stat.unipg.it/luca V_/_ V_/_ V_/_ |
+-----------------------------------------------------------------------+ ______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon May 16 21:52:14 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:46 EST