Tip:
Highlight text to annotate it
X
In addition to the work space, another thing that R is doing that isn't readily
apparent, is that R is currently monitoring, a specific folder on your
computer. This is called the working directory, and
this is the first place that R's gonna look when you ask it to import a file
without giving full path on your computer to that file.
So, if you're curious what your current working directory is, you can type the
function get WD. Wd standing for working directory.
Remember you parentheses, and hit enter. And you'll see that my current working
directory, since I have not changed the default, is just my Documents folder.
You can also set your working directory if you know where you want to go and you
just, just for this session only want to set it, you can use set wd, so set working
directory and then type in a working directory.
So I know, actually I don't know all the different folders I have in here, but if I
had some new working directory folder I wanted to go into, I could type it in like
that and hit enter and it would change, but.
That folder's match exists, so that's just going to throw an error.
So, I want to hang there. Just to help those of you might not have
ever thought about paths in this kind of way.
If you used to thinking of your computer as a series of embedded folders, this kind
of address right here might look really intimidating.
It's actually pretty easy to follow. So, starting from the left, each of the
names is just the name of a folder. And you're going, so, here you're starting
at the top level. So, my Macintosh hard drive, I start at
the root of that. To get to my Documents folder, I then, if
you, you can just imagine yourself clicking into Users, then clicking into
Elasto, then clicking into Documents, and that's just what the "path" means.
So, what if you want to change your working directory?
So, imagine you want to find a specific file, and you want to get to that
directory and set it as your working directory.
So one easy way to do that in Mac, I'm just going to pop in here with my stats
materials, you can see I downloaded the data set for Lecture three.
And we're going to be working with that in a little bit.
For now, I've just downloaded it. So, it's actually on my desktop.
But with it in stats materials folder I have some data, and then in there I have
my supplemental stats. So, if you want, if I just want to get the
path to this file. I can go to here.
Get info. You see you're not actually gonna see a
preview of it, but what you really need is right here.
So where? So, this is the path, to the data folder,
where this file lives. So, if I wanted to just set my working
directory, I could, terminate with quotes around it, cuz it's a string.
Let's do that. And now if I do get WD, I've actually
moved. So, that's one way to do it.
Keep in mind though, if you set your working directory as manually any time you
close out, it's going to revert back to whatever your default working directory
is. I have to recommend to my students that
they just create a folder for whatever stuff they are working on.
And change their default working directory to that folder, so they don't have to do
this confusing shuffle.To do that on a Mac, you would go to R.
Any preferences and within the preferences, it actually will start here.
You'll see there is a start up button it might be up here but either one the r
start up. There's a lot of different options right
here initial working directory this is your default so it's initial anytime you
open r this is where it's going to default to.
So you can see minus documents. So to change that, you can just click the
change button and this should hopefully look more familiar just navigating so it's
going users, all subtle. I actually want to go to my desktop
because that where my materials live. So desktop has my materials then I'm
always gonna put my data here. So I'll just hit open and you can see now
that is where it goes. I check always apply just because I like
the firmness of it. [laugh] Always apply I haven't see a
difference checking it or unchecking it I think by default it's not checked but
either way.... I think then you can just close it and it
will have done it. So just to prove that to you let me kind
of clear out of everything. You see, actually you can see right here.
In Mac, it'll always say, where your working directory is.
So you can see I'm actually where I was supposed to be.
Just to show you, the forget WD command, I'm now in my data folder.
And so now every time I start up, it's gonna go there.