[R-sig-teaching] workspace management
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Nov 2 18:52:28 CET 2010
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:
>>
>> 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.
>>
>> 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.
>>
>>
>> --
>> Statistics & Software Consulting
>> GKX Group, GKX Associates Inc.
>> tel: 1-877-GKX-GROUP
>> email: ggrothendieck at gmail.com
>
>
>
> --
> Ralph O'Brien, PhD
> Professor, Dept of Epidemiology and Biostatistics
> Case Western Reserve University
> Office: 216.368.1927
> Cell: 216.312.3203
>
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-sig-teaching
mailing list