Advertisement
English transcript
Hi! I am Mike Marin and in this video
we'll talk about setting up your working directory. working directories
are useful for keeping your work organized. a working directory
is one spot say a folder that you've created
for saving all of your work such as code you've written
the current workspace, any plots or summaries produced and so on
all will be saved to the current working directory
it's a good idea to create a different working directory
for each project that you work on. I've already gone ahead
and created a folder named "Project 1" and saved it on my desktop
we will set this up to be the current working directory
I've also gone ahead and read in the LongCapData
that we've been working with in this series of videos. to find out what the
current working directory
is you can use the "getwd" command
right now we can see that the current working directory
is the main folder in my user account. we can set the working directory
in a few different ways. first we can use the
"setwd" command in R; to use this command
we must specify the path to the folder we would like to set as our working directory
I've already found the path to this folder "Project 1"
and copied it so I'll go ahead and paste it in here. it's worth noting
we don't need to specify the full path to this folder "Project 1"
we can make use of the tilde (~) command
to let R know we'd like the path up until the desktop
and then to "Project 1"; I will now
show you a little tip that may become useful in the future for you
we can create this object "projectWD"
for working directory and specify the path
to the working directory or this folder "Project 1" we'd like to save in. we can
then go ahead
and set our working directory using this
object "projectWD"
at the moment doing this may seem pointless to you but as we get better with
R and coding you will be able to see the use of doing something like this
we may also use the menus in R to set the working directory
to do so we can go use the "Session" menu
under here we can see this
"Set Working Directory" and "Choose (working) Directory..."
this will bring this to a menu where we can select the "Project 1" folder
it's worth noting that in previous versions
of RStudio the "Set Working Directory" could be found under the "Tools" menu
not under the "Session" menu. a pro
of using the menu approach to setting the working directory is that it can be
easier
if you're not as comfortable writing codes or working with R just yet it
a pro of
using code to set the working directory is that in the future
if you're writing a script of code and working with this
you will find that'll be much easier to have all this done in code
rather than having to use our hands and click on menu items. in a later video in
this series
I'll show you how you can change the default working directory
permanently using RStudio preferences. now
it's a good idea to check the current working directory
and make sure we did this correctly so let's check what the current working
directory is
and we can see it's now this folder "Project 1";
okay, so now's the part where we probably do some work. let's suppose
we wanted to create some object "MeanAge" and will save in this
the "mean(Age)", we also may have created few other objects in our work
let's say some vector x 1,2,3,4,5
some other object y
which takes on a value of 14 and an object z
which is a summary of the data
you'll also notice
I used the equal sign here to assign the summary
to the object z just as a reminder that we can use the equal sign
or the arrow. now suppose that we're done working for the day
and we'd like to save our progress. again we can do this using code
or using the menus; we can save our current workspace image
using the "save.image" command
in here we can specify what we'd like to save the file as
I'll save it under the name "FirstProject"
and we should add the extension ".Rdata"
this will let R know that this is a workspace image file
it's also worth mentioning that without specifying a path
of where this file should be saved it will be saved in the current working directory
we can also use the menus in RStudio to save the workspace image
to do so we can go under the "Session" menu
"Save Workspace As..."; again
just a previous note on earlier versions of RStudio
the "Save Workspace" could be found under the "Workspace" menu
you see the new version of RStudio no longer has "Workspace"
as a menu item!
it's also worth noting that upon quitting R
you should be prompted as to whether or not you'd like to save the current
workspace image.
now let's go ahead and clear the workspace and quit R
recall that we can remove all items from the current workspace
using the following command:("rm(list=ls()")
or we can also use the menus and click on "Session"
and "Clear Workspace..."
we can quit RStudio by going here
and choosing "Quit RStudio" or using commands
we can type "q" and open and close brackets ()
you'll see here that we're prompted as to whether or not we'd like to save the
workspace image
I'm gonna click No as we've already gone ahead and save this
okay suppose it is the next time you're going to work on this project
as you can see I've gone ahead and launched RStudio
and we can see that there's nothing in the current working directory
we can check this using commands or by looking at the workspace
in RStudio. now we like to load the workspace for "Project 1"
from where we left off last time. upon starting our new session
we should go ahead and set the working directory. we can do this
as outlined earlier using code or menus
I'm gonna go ahead and do it using code here. we'd like to
set our working directory running up to the desktop
and then the folder "Project 1"
we can check to make sure we've done this correctly
and we can see our current working directory
we can then go ahead and load the previous workspace image
using the "load" command and here specifically
we would like to load this file "FirstProject.Rdata"
you'll notice we haven't specified the path to this file
as this file is saved in the current working directory
we can now see we've loaded the previous workspace image
we can also load the workspace image using the
"file.choose" command that we've learned earlier
doing this will allow you to select the file
from a menu. I'm gonna cancel this option as we've already loaded the workspace
we can also use the menus in RStudio. again we can find this
under the "Session" menu and "Load Workspace..."
it's also worth noting again here that in previous versions
of "RStudio" you could load the workspace from a "Workspace" menu item
the "Workspace" menu item has now been replaced by this "Session" menu.
in the next video in this series
we'll talk about writing and using scripts of code
and the benefit of these.
thanks for watching this video and make sure to check out my other instructional videos
we'll talk about setting up your working directory. working directories
are useful for keeping your work organized. a working directory
is one spot say a folder that you've created
for saving all of your work such as code you've written
the current workspace, any plots or summaries produced and so on
all will be saved to the current working directory
it's a good idea to create a different working directory
for each project that you work on. I've already gone ahead
and created a folder named "Project 1" and saved it on my desktop
we will set this up to be the current working directory
I've also gone ahead and read in the LongCapData
that we've been working with in this series of videos. to find out what the
current working directory
is you can use the "getwd" command
right now we can see that the current working directory
is the main folder in my user account. we can set the working directory
in a few different ways. first we can use the
"setwd" command in R; to use this command
we must specify the path to the folder we would like to set as our working directory
I've already found the path to this folder "Project 1"
and copied it so I'll go ahead and paste it in here. it's worth noting
we don't need to specify the full path to this folder "Project 1"
we can make use of the tilde (~) command
to let R know we'd like the path up until the desktop
and then to "Project 1"; I will now
show you a little tip that may become useful in the future for you
we can create this object "projectWD"
for working directory and specify the path
to the working directory or this folder "Project 1" we'd like to save in. we can
then go ahead
and set our working directory using this
object "projectWD"
at the moment doing this may seem pointless to you but as we get better with
R and coding you will be able to see the use of doing something like this
we may also use the menus in R to set the working directory
to do so we can go use the "Session" menu
under here we can see this
"Set Working Directory" and "Choose (working) Directory..."
this will bring this to a menu where we can select the "Project 1" folder
it's worth noting that in previous versions
of RStudio the "Set Working Directory" could be found under the "Tools" menu
not under the "Session" menu. a pro
of using the menu approach to setting the working directory is that it can be
easier
if you're not as comfortable writing codes or working with R just yet it
a pro of
using code to set the working directory is that in the future
if you're writing a script of code and working with this
you will find that'll be much easier to have all this done in code
rather than having to use our hands and click on menu items. in a later video in
this series
I'll show you how you can change the default working directory
permanently using RStudio preferences. now
it's a good idea to check the current working directory
and make sure we did this correctly so let's check what the current working
directory is
and we can see it's now this folder "Project 1";
okay, so now's the part where we probably do some work. let's suppose
we wanted to create some object "MeanAge" and will save in this
the "mean(Age)", we also may have created few other objects in our work
let's say some vector x 1,2,3,4,5
some other object y
which takes on a value of 14 and an object z
which is a summary of the data
you'll also notice
I used the equal sign here to assign the summary
to the object z just as a reminder that we can use the equal sign
or the arrow. now suppose that we're done working for the day
and we'd like to save our progress. again we can do this using code
or using the menus; we can save our current workspace image
using the "save.image" command
in here we can specify what we'd like to save the file as
I'll save it under the name "FirstProject"
and we should add the extension ".Rdata"
this will let R know that this is a workspace image file
it's also worth mentioning that without specifying a path
of where this file should be saved it will be saved in the current working directory
we can also use the menus in RStudio to save the workspace image
to do so we can go under the "Session" menu
"Save Workspace As..."; again
just a previous note on earlier versions of RStudio
the "Save Workspace" could be found under the "Workspace" menu
you see the new version of RStudio no longer has "Workspace"
as a menu item!
it's also worth noting that upon quitting R
you should be prompted as to whether or not you'd like to save the current
workspace image.
now let's go ahead and clear the workspace and quit R
recall that we can remove all items from the current workspace
using the following command:("rm(list=ls()")
or we can also use the menus and click on "Session"
and "Clear Workspace..."
we can quit RStudio by going here
and choosing "Quit RStudio" or using commands
we can type "q" and open and close brackets ()
you'll see here that we're prompted as to whether or not we'd like to save the
workspace image
I'm gonna click No as we've already gone ahead and save this
okay suppose it is the next time you're going to work on this project
as you can see I've gone ahead and launched RStudio
and we can see that there's nothing in the current working directory
we can check this using commands or by looking at the workspace
in RStudio. now we like to load the workspace for "Project 1"
from where we left off last time. upon starting our new session
we should go ahead and set the working directory. we can do this
as outlined earlier using code or menus
I'm gonna go ahead and do it using code here. we'd like to
set our working directory running up to the desktop
and then the folder "Project 1"
we can check to make sure we've done this correctly
and we can see our current working directory
we can then go ahead and load the previous workspace image
using the "load" command and here specifically
we would like to load this file "FirstProject.Rdata"
you'll notice we haven't specified the path to this file
as this file is saved in the current working directory
we can now see we've loaded the previous workspace image
we can also load the workspace image using the
"file.choose" command that we've learned earlier
doing this will allow you to select the file
from a menu. I'm gonna cancel this option as we've already loaded the workspace
we can also use the menus in RStudio. again we can find this
under the "Session" menu and "Load Workspace..."
it's also worth noting again here that in previous versions
of "RStudio" you could load the workspace from a "Workspace" menu item
the "Workspace" menu item has now been replaced by this "Session" menu.
in the next video in this series
we'll talk about writing and using scripts of code
and the benefit of these.
thanks for watching this video and make sure to check out my other instructional videos