Laura Chihara | 1 Nov 2010 22:32

workspace management

hello!

I'm wondering how you have your students
handle workspaces in R. Do you have students
create their own R folder (on their home drive),
and then load from within R? Or do you
have them create an R shortcut and then
type the path in the "Start In" field (Windows)?

I've been teaching the latter method, but am
wondering if loading from within R is easier?

Thanks for ideas.

--Laura

*******************************************
Laura Chihara
Professor of Mathematics   507-222-4065 (office)
Dept of Mathematics        507-222-4312 (fax)
Carleton College
1 North College Street
Northfield MN 55057

Murray Jorgensen | 2 Nov 2010 02:09
Picon
Picon
Favicon

Re: workspace management

I think that folders should be organized by topic and not by the 
software that might use the files. After all you might want to use 
several different applications of files in a folder.

I teach doing something like this at the start of an R script:

 > wdir <- choose.dir()
 > wdir
[1] "C:\\Files\\Teaching\\STAT321\\2008"
 > setwd(wdir)

Later you can edit this to

wdir <- # choose.dir()
        "C:\\Files\\Teaching\\STAT321\\2008"
setwd(wdir)

to avoid repeating the dialog boxes.

Murray

On 2/11/2010 10:32 a.m., Laura Chihara wrote:
> hello!
>
> I'm wondering how you have your students
> handle workspaces in R. Do you have students
> create their own R folder (on their home drive),
> and then load from within R? Or do you
> have them create an R shortcut and then
> type the path in the "Start In" field (Windows)?
(Continue reading)

Ralph O'Brien, PhD | 2 Nov 2010 17:51
Picon

Re: workspace management

A huge plus for R is that it runs nearly identically on all three major
platforms. There is every reason to make our teaching as
platform-independent as we can.

The choose.dir() function is not found on the Mac release (I'm still at v.
2.11.1), so I would advise against using it, especially since it is trivial
to teach and use code that is "plain vanilla."

My scripts to students begin with something like:

# Uncomment one of these path2data statements and
# insert your appropriate path specification.
# path2data <- "C:/EPBI431/datasets"   # Windows (convert to forward
slashes)
 # path2data <- "/Users/ralphobrien/AllDocs/teaching/EPBI431/datasets"   #
Mac OS
setwd(path2data)

Later, I might simply give them:

# setwd("C:/EPBI431/datasets")  # Windows (convert to forward slashes)
# setwd("/Users/ralphobrien/AllDocs/teaching/EPBI431/datasets")  # Mac OS

Some students have never encountered path specifications, so when I
introduce this, I show them how to use "Properties" (Windows XP) and "Get
Info" (Mac OS) to copy-paste what is needed, converting the back slashes to
forward slashes for Windows.

In the real world, there are also strong programming integrity reasons to
hard code paths directly into our scripts. This leaves no doubt about what
(Continue reading)

Gabor Grothendieck | 2 Nov 2010 18:24
Picon

Re: workspace management

On Tue, Nov 2, 2010 at 12:51 PM, Ralph O'Brien, PhD
<obrienralph <at> gmail.com> wrote:
> A huge plus for R is that it runs nearly identically on all three major
> platforms. There is every reason to make our teaching as
> platform-independent as we can.
>
> The choose.dir() function is not found on the Mac release (I'm still at v.
> 2.11.1), so I would advise against using it, especially since it is trivial
> to teach and use code that is "plain vanilla."
>
> My scripts to students begin with something like:
>
> # Uncomment one of these path2data statements and
> # insert your appropriate path specification.
> # path2data <- "C:/EPBI431/datasets"   # Windows (convert to forward
> slashes)
>  # path2data <- "/Users/ralphobrien/AllDocs/teaching/EPBI431/datasets"   #
> Mac OS
> setwd(path2data)
>
> Later, I might simply give them:
>
> # setwd("C:/EPBI431/datasets")  # Windows (convert to forward slashes)
> # setwd("/Users/ralphobrien/AllDocs/teaching/EPBI431/datasets")  # Mac OS
>
> Some students have never encountered path specifications, so when I
> introduce this, I show them how to use "Properties" (Windows XP) and "Get
> Info" (Mac OS) to copy-paste what is needed, converting the back slashes to
> forward slashes for Windows.

(Continue reading)

Ralph O'Brien, PhD | 2 Nov 2010 18:44
Picon

Re: workspace management

========================
If you have a path with backslashes in the Windows clipboard you can
just do this:

myPath <- readClipboard()
setwd(myPath)

which eliminates the need for any conversion.
========================

But this is still Windows-centric functionality (not platform independent)
and it hides what dataset was in play (not a good programming practice in
the real world).

On Tue, Nov 2, 2010 at 1:24 PM, Gabor Grothendieck
<ggrothendieck <at> gmail.com>wrote:

> On Tue, Nov 2, 2010 at 12:51 PM, Ralph O'Brien, PhD
> <obrienralph <at> gmail.com> wrote:
> > A huge plus for R is that it runs nearly identically on all three major
> > platforms. There is every reason to make our teaching as
> > platform-independent as we can.
> >
> > The choose.dir() function is not found on the Mac release (I'm still at
> v.
> > 2.11.1), so I would advise against using it, especially since it is
> trivial
> > to teach and use code that is "plain vanilla."
> >
> > My scripts to students begin with something like:
(Continue reading)

Gabor Grothendieck | 2 Nov 2010 18:52
Picon

Re: workspace management

On Tue, Nov 2, 2010 at 1:44 PM, Ralph O'Brien, PhD
<obrienralph <at> gmail.com> wrote:
> ========================
> If you have a path with backslashes in the Windows clipboard you can
> just do this:
>
> myPath <- readClipboard()
> setwd(myPath)
>
> which eliminates the need for any conversion.
> ========================
>
> But this is still Windows-centric functionality (not platform independent)
> and it hides what dataset was in play (not a good programming practice in
> the real world).

You are already converting backslashes to forward slashes which is
only needed for Windows; however, we can make this completely generic
by using:

myPath <- readLines("clipboard")

which works on Windows and Linux and maybe Mac (I don't have one).  If
you don't have a newline in your clipboard it will give a warning on
Windows but you can ignore that as it will still work.

>
> On Tue, Nov 2, 2010 at 1:24 PM, Gabor Grothendieck <ggrothendieck <at> gmail.com>
> wrote:
>>
(Continue reading)

William Revelle | 2 Nov 2010 20:45

Re: workspace management

My solution is a bit different.

Most student oriented files are relatively small (less than 1 MB) and 
can just be copied to the clipboard from their editor/spreadsheet 
progam.

Most students know how to open excel or text files.  I have them do 
that and then just copy the data to the clipboard (from Excel or 
OpenOffice or Word or their favorite text editor)

then,
my.data <- read.clipboard()   #from the psych package

and their data are in a suitable format.
If they are copying from excel,
my.data <- read.clipboard.tab()  #will read directly from an Excel file
my.data <- read.clipboard.csv()  # will read from a file in comma 
delimited form.
etc.

The one problem I have had doing this is some student's do not know 
what the clipboard is!

Bill

At 1:44 PM -0400 11/2/10, Ralph O'Brien, PhD wrote:
>========================
>If you have a path with backslashes in the Windows clipboard you can
>just do this:
>
(Continue reading)

Hadley Wickham | 2 Nov 2010 19:23
Favicon
Gravatar

Re: workspace management

> In the real world, there are also strong programming integrity reasons to
> hard code paths directly into our scripts. This leaves no doubt about what
> dataset was being analyzed, etc.

The whole point of using a working directory is so that you _don't_
have to do that.  Any hard coded path makes reproduction on another
computer a real pain - you should always rely on the analyst setting
the working directory from outside of the script, otherwise you lose
most of the advantages of a working directory.

Hadley

--

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Murray Jorgensen | 2 Nov 2010 23:05
Picon
Picon
Favicon

Re: workspace management

Actually I find a hard-coded path *especially* useful when I'm using 
more than one computer as it reminds me of what directory I'm suppose to 
be working in.

I write code like

wbf =  #"C:\\Files\\Consulting\\Cilla\\Wetaboxes 1.7.09.csv"
   "C:\\Users\\maj\\Documents\\Consulting\\Cilla\\Wetaboxes 1.7.09.csv"
longterm = read.csv(wbf,header=TRUE)

and move the # around depending on what computer I'm on.

Murray

On 3/11/2010 7:23 a.m., Hadley Wickham wrote:
>> In the real world, there are also strong programming integrity reasons to
>> hard code paths directly into our scripts. This leaves no doubt about what
>> dataset was being analyzed, etc.
>
> The whole point of using a working directory is so that you _don't_
> have to do that.  Any hard coded path makes reproduction on another
> computer a real pain - you should always rely on the analyst setting
> the working directory from outside of the script, otherwise you lose
> most of the advantages of a working directory.
>
> Hadley
>

--

-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
(Continue reading)

Hadley Wickham | 2 Nov 2010 23:13
Favicon
Gravatar

Re: workspace management

> Actually I find a hard-coded path *especially* useful when I'm using more
> than one computer as it reminds me of what directory I'm suppose to be
> working in.
>
> I write code like
>
> wbf =  #"C:\\Files\\Consulting\\Cilla\\Wetaboxes 1.7.09.csv"
>  "C:\\Users\\maj\\Documents\\Consulting\\Cilla\\Wetaboxes 1.7.09.csv"
> longterm = read.csv(wbf,header=TRUE)
>
> and move the # around depending on what computer I'm on.

But that's exactly what the idea of a working directory is to avoid.
Just set all paths relative to the R file, and then set the working
directory (or use source + chdir = T) and you're golden.  Admittedly
this works best from the command line, where the directory you start R
from becomes the working directory.

Hadley

--

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

david monterde | 6 Dec 2010 12:27

Re: workspace management

I use the select.list when I have welldefined the paths and the fix function when not
I start idetifyind the unit, and then the rest of the path:

   unit   <- select.list(paste(letters,":/",sep=""))
   paths <- c("Projects/Data/", "MyPenDrive/Projects/Data")
   path  <- select.list(paths)
   path  <- paste(unit,path,sep="")

So I can work with the same program in any computer using my pendrive, or in my computer using my own path.

If there is not a fixed path:

   path <- "c:/new path/"
   fix(path)

You can use the select-list function to choose between different platforms, (Linux, Mac, Windows):

   OS   <- select.list("Lunix,"Mac","Windows")
   if (OS=="Linux") then { # use the select.list function with paths in Linux format (//users//) }
   if (OS=="Windows") then { # use the select.list function with paths in Linux format (c:/) }

Sorry by my english,

david

El 02/11/2010, a las 23:13, Hadley Wickham escribió:

>> Actually I find a hard-coded path *especially* useful when I'm using more
>> than one computer as it reminds me of what directory I'm suppose to be
>> working in.
(Continue reading)

Gabor Grothendieck | 6 Dec 2010 12:38
Picon

Re: workspace management

On Mon, Dec 6, 2010 at 6:27 AM, david monterde <dmonterde <at> me.com> wrote:
> I use the select.list when I have welldefined the paths and the fix function when not
> I start idetifyind the unit, and then the rest of the path:
>
>   unit   <- select.list(paste(letters,":/",sep=""))
>   paths <- c("Projects/Data/", "MyPenDrive/Projects/Data")
>   path  <- select.list(paths)
>   path  <- paste(unit,path,sep="")
>
> So I can work with the same program in any computer using my pendrive, or in my computer using my own path.
>
> If there is not a fixed path:
>
>   path <- "c:/new path/"
>   fix(path)
>
> You can use the select-list function to choose between different platforms, (Linux, Mac, Windows):
>
>   OS   <- select.list("Lunix,"Mac","Windows")
>   if (OS=="Linux") then { # use the select.list function with paths in Linux format (//users//) }
>   if (OS=="Windows") then { # use the select.list function with paths in Linux format (c:/) }
>

You can detect windows vs. unix using .Platform$OS eliminating a
question to the user.  See ?.Platform

--

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
(Continue reading)


Gmane