Where am I?

September 22, 2018
By

(This article was first published on HighlandR, and kindly contributed to R-bloggers)

Notes on the here package –

The here package is pretty simple ( only 3 functions), but I cannot remember how to use it to navigate folders, so this is my aide-memoire.
It might be useful for others too.

Here finds the root of your current folder / working directory.
If you use Projects in RStudio, that will usually be the root of your project folder.
If not, you can use set_here() to create a small file which will set the root location.


# where am I in my computer?
here()

"C:/Users/some/path/or/other"

#
# create a folder
dir.create(here("img"))
"C:/Users/some/path/or/other/img"

dir.create(here("img","png"))
"C:/Users/some/path/or/other/img/png"


#move to the outputs folder using setwd()
setwd(here("img"))

# check this worked - get the current working directory with  getwd()
getwd()

"C:/Users/some/path/or/other/img"

# go back to the root of the project
setwd(here())

#check you are back where you started

getwd()

"C:/Users/some/path/or/other"

Now the next time I am like this:

¯_(ヅ)_/¯

I can just read this post, and hope no-one sees me reading my own blog.

To leave a comment for the author, please follow the link and comment on their blog: HighlandR.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)