# A path is the location on your computer (think of a folder) which R uses to
# look for datasets you call and to store things you tell it to store. Here's
# how we can define and change the path (note that, in order to run this code,
# you need to insert paths that work for your own computer):
# Have a look at the folder (path) that R is currently in:
getwd() # 'get working directory'
# Change the path:
setwd("/Users/markomlikota/Documents/MySpecialFolder")
# If you regularly go between different paths/folders, it makes sense to define
# them first:
sMyPath = "/Users/markomlikota/Documents/MySpecialFolder"
setwd(sMyPath)
# Change the path to a sub-folder inside 'MySpecialFolder':
setwd(paste(sMyPath, "/MySubFolder", sep = ""))
# again, it might make sense to store this path:
sMySubPath = paste(sMyPath, "/MySubFolder", sep = "")
setwd(sMySubPath)
# Paths are computer-specific. However, if you collaborate with others via
# Dropbox, you can define the path relative to the Dropbox folder, so that
# everyone can use the same path definition and hence run the same code:
setwd("~/Dropbox/OurSpecialFolder")
# (This works provided that everyone has 'OurSpecialFolder' in the same
# location inside their Dropbox.)
# We can also use R to create and delete folders in our path (i.e. on our
# computer):
# List all folders in the current path:
dir()
# Create a folder 'abc' in the current path:
dir.create("abc")
# Verify whether folder 'abc' exists in current path:
dir.exists("abc")
# Delete folder 'abc' in current path: (need computer's permission for that)
unlink("abc")