zhrandell / Seattle_Aquarium_CCR_analytical_resources

This is a public repository to organize information pertaining to the cleaning, analysis, and visualization of ROV telemetry and spatial data, as well as preliminary information related to the % cover analyses (via CoralNet) of image stills derived from ROV video.
8 stars 0 forks source link

Setting general working directory #5

Closed m-h-williams closed 2 years ago

m-h-williams commented 2 years ago

To avoid resetting the working directory for each user of the a script in this repo we can use the 'here' package. "The goal of the here package is to enable easy file referencing in project-oriented workflows . In contrast to using setwd(), which is fragile and dependent on the way you organize your files, here uses the top-level directory of a project to easily build paths to files."

Skip if you have already made an Rproject with the cloned repo (instructions from https://happygitwithr.com/rstudio-git-github.html) Start by cloning the GitHub repository to your computer and creating a new project via RStudio: File > New Project > Version Control > Git. In “Repository URL”, paste the URL of your new GitHub repository.

Accept the default project directory name, e.g. myrepo, which coincides with the GitHub repo name.

Take charge of – or at least notice! – where the Project will be saved locally.

Click “Create Project”


After installing the package 'here' install.packages("here") we can use setwd(here::here()) at the top of each script within the RProject. here::here() works like file.path() , but where the path root is set to “the path to the top-level of my current project”.

Now to read and write files you set the path that is already within the cloned repo, which should be same the same for each user. https://github.com/zhrandell/Seattle_Aquarium_ROV_telemetry_imagery_analysis/blob/c36826203866203562bc195221bbff1db16e5d98/code/Avg_Ping.R#L10

https://github.com/zhrandell/Seattle_Aquarium_ROV_telemetry_imagery_analysis/blob/c36826203866203562bc195221bbff1db16e5d98/code/Avg_Ping.R#L45

@zhrandell want to try running the Avg_Ping.R script as is and seeing if this works for you? https://github.com/zhrandell/Seattle_Aquarium_ROV_telemetry_imagery_analysis/blob/c36826203866203562bc195221bbff1db16e5d98/code/Avg_Ping.R

m-h-williams commented 2 years ago

Pushing commits through the R project is not working for me, but GitHb desktop still works just fine.

Threads suggest this may be a Mac issue so @zhrandell it might work for you once you get the R project working.

m-h-williams commented 2 years ago

I was able to successfully connect RStudio and GitHub on my Mac by modifying the instructions from https://www.geeksforgeeks.org/link-your-github-account-with-r-studio/ Instead of inputting the web URL for the repo when creating a new project, I inputted in the SSH key (git@github.com:zhrandell/Seattle_Aquarium_ROV_telemetry_imagery_analysis.git)

zhrandell commented 2 years ago

Nice, well done @m-h-williams! I pulled this repo, opened the R project, and was able to push a test commit once I set up a Personal Access Token (curiously, I didn't have to re-clone like you did). I then confirmed that I can still push via GitHub Desktop as well. Yay, it looks like we're fully connected!

zhrandell commented 2 years ago

And thanks @m-h-williams, I open Avg_Ping.R and was indeed able to use the generalized working directory via setwd(here::here()). The .csv file opened up no problem. Nicely done! :-)

zhrandell commented 2 years ago

Nicely done, @m-h-williams! closing now