grunwaldlab / Population_Genetics_in_R

A primer for computational tools to analyze genetics of populations in R
http://grunwaldlab.github.io/Population_Genetics_in_R
Other
84 stars 50 forks source link

Files not in cwd #36

Closed knausb closed 6 years ago

knausb commented 6 years ago

New users may attempt to open files when r is not in the correct working directory. We should explain what the current working directory is and how to query the files in it.

zkamvar commented 6 years ago

A good way to do this is to use the here package. That way they can use a file anchor point such as an rstudio project, git repo, or an empty file called “.here”

Sent from my iPhone

On Jul 29, 2018, at 13:32, Brian Knaus notifications@github.com wrote:

New users may attempt to open files when r is not in the correct working directory. We should explain what the current working directory is and how to query the files in it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

knausb commented 6 years ago

I'm not familiar with here, I'll look into it. My usual is to suggest getwd() and list.files() to determine where they are.

grunwald commented 6 years ago

Alternative would be to download the files from within R if workshop has WiFi. That should get around it?

On Jul 29, 2018, at 9:26 AM, Brian Knaus notifications@github.com wrote:

I'm not familiar with here, I'll look into it. My usual is to suggest getwd() and list.files() to determine where they are.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/grunwaldlab/Population_Genetics_in_R/issues/36#issuecomment-408677809, or mute the thread https://github.com/notifications/unsubscribe-auth/ADglOnEAxW_vQ_faTwmpdtzalHSvxSh6ks5uLbgjgaJpZM4VlZ2g.

zkamvar commented 6 years ago

@knausb, I found this blogpost to be a good introduction behind the rational for using here: https://www.tidyverse.org/articles/2017/12/workflow-vs-script/

knausb commented 6 years ago

Thanks @zkamvar for a nice post! I can't count the number of times my scripts began with

setwd("C:\Users\jenny\path\that\only\I\have")
rm(list = ls())

in my pre-Rstudio days. I think the concept of an Rstudio Project circumvents this nicely. I'm not sure I appreciate the beauty of here yet. At the present, it seems like a reinvention of existing functions to me. I'll try to work on a PR to propose a solution, sometimes doing illustrates things.

zkamvar commented 6 years ago

I think the main benefit of here is you can have a more organized folder structure for your scripts and figures since here will search up the directory tree until it finds the root of the project.

So, if you have a script in scripts/plotThis.Rmd, and you want to write a plot to figs/thisPlot.svg, you can use:

svg(here::here("figs", "thisPlot.svg") plot(x) dev.off()

Inside of the script and it will work wherever you are in the directory tree.

On Aug 3, 2018, at 15:22 , Brian Knaus notifications@github.com wrote:

Thanks @zkamvar https://github.com/zkamvar for a nice post! I can't count the number of times my scripts began with

setwd("C:\Users\jenny\path\that\only\I\have") rm(list = ls()) in my pre-Rstudio days. I think the concept of an Rstudio Project circumvents this nicely. I'm not sure I appreciate the beauty of here yet. At the present, it seems like a reinvention of existing functions to me. I'll try to work on a PR to propose a solution, sometimes doing illustrates things.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/grunwaldlab/Population_Genetics_in_R/issues/36#issuecomment-410265725, or mute the thread https://github.com/notifications/unsubscribe-auth/ADeIlnoVlKS-qaL3wwMZgzpbv7bFPwkvks5uNFySgaJpZM4VlZ2g.

knausb commented 6 years ago

Addressed at: ff36c92eb8532886e24740d9d976546736345a69