[R] Can't there be a cd command?

Gabor Grothendieck ggrothendieck at gmail.com
Wed May 10 16:45:07 CEST 2006


On 5/10/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 5/10/2006 9:29 AM, Paul Johnson wrote:
> > It is a FAQ in our Linux lab.  People start emacs and fire up R via
> > ess, and then they have no idea 'where they are".  For computer
> > experts, it is not a problem, but for people who don't know much about
> > computers, it is a pretty big problem.  They have data in some
> > subdirectory, but almost invariably they don't get emacs & R started
> > from that same place.
> >
> > Unfortunately, for our users, it does not help to simply re-label
> > setwd as cd.  Both commands imply a deeper understanding of the OS
> > than they have.  Also, unfortunately, these are the same people who
> > don't understand that FAQs exist and should be consulted. These people
> > are so new/timid that asking in r-help would be the last thing to
> > cross their mind.
> >
> > I've wondered if it would not help to have the R prompt include the
> > directory name, as in an x terminal.
>
> I think file system directories aren't as central in R as they are in a
> shell, so it would just be distracting.  Most of the time I work in the
> R workspace, not in the file system.
>
> To me the solution is to allow interactive file selection by default,
> i.e. the default on read.table and similar functions should be
> file.choose(), rather than having no default and throwing an error.
> This won't help you in the short run (because file.choose() on Linux
> isn't all that friendly to beginners), but perhaps it would encourage
> someone to make it better.  file.choose() is quite nice in Windows (and
> I think on the Mac), so beginners there could be told
>
> mydf <- read.table()
>
> and they'd get something useful.
>
> Martin Maechler has disagreed with me about this in the past, but hasn't
> convinced me that he's right, he's just convinced me that doing nothing
> is easier than arguing about it.

I agree with Martin regarding read.table; however, the underlying idea is
good and could be achieved via simple wrappers which are the same
as the corresponding underlying functions except for the default argument
to file:

   read.table.choose <- function(file = file.choose(), ...)
read.table(file, ...)
   read.csv.choose <- function(file = file.choose(), ...) read.csv(file, ...)
   read.delim.choose <- function(file = file.choose(), ...)
read.delim(file, ...)

  # test
  mydata <- read.table.choose()

in a package available to the users or possibly even in R core.




More information about the R-help mailing list