geco-bern / agds

Applied Geodata Science book. Developed for the lecture(s) with the same name at the Institute of Geography, University of Bern.
https://geco-bern.github.io/agds/
Other
5 stars 6 forks source link

Confusing RMarkdown working directory #123

Open pepaaran opened 1 year ago

pepaaran commented 1 year ago

When and RMarkdown that is saved somewhere outside of the project folder is opened in RStudio, it uses its location as working directory, not the location of the project. Hence, it's very confusing for students that code run in the chunks may work but the console doesn't and vice versa. This is because the console and the R chunks have different working directories! We need to somehow clarify this without making it overly complicated.

khufkens commented 1 year ago

This relates to #125 Basically they must get the notion of a path, and then relative and absolute paths of execution environments (when hitting render).

The easy solution is that everyone wraps their paths in here::here() no rubbish with . and ../, only work relative from the project path.

pepaaran commented 1 year ago

I just noticed that, by default, .Rmd take as working directory the file's location, rather than the project directory. I had understood that working with projects uses here implicitly, but judging from your comment @khufkens I guess that's not true. Nevertheless, it can be specified that the "knit directory" should coincide with the project directory and this information is saved for the consecutive R sessions. Would this be an easy solution?

image

In my opinion, we should still explain paths like Beni suggests in #125. It's basic and important computer knowledge.

khufkens commented 1 year ago

I've had very inconsistent results with trying to nest non-book related Rmd in sub directories and rendering them succesfully with the knitr button.

I put my presentations for the lessons in GECO_media because of this. These are ioslides Rmd files, and for the life of me I could not get them to render as not a book (even when selecting the knit directory in the drop down). YMMV depending on the type, but for presentations at least this did not work at all.

khufkens commented 1 year ago

Note that this is for the particular case of a bookdown project, not a general R project. More settings are implied which might override default behaviour.

khufkens commented 1 year ago

So, in short, try it with the template and if this works we are good (or it can be used as such without the need to teach paths and or {here}).

pepaaran commented 1 year ago

I made this project from the template, so the template does not solve the issue of rendering in the root directory...

pepaaran commented 1 year ago

By the way, some students were having problems with rendering their Rmd because they had it in a separate folder, outside of the project. This is because they were not very organized with the exercise solutions, compared to the report project they started. So... I'm not sure we will be able to avoid explaining paths and working directories, thoughts?

khufkens commented 1 year ago

It is really hard to avoid I fear. It's also a basic notion on the structure of files / data. So, not a bad thing.

stineb commented 1 year ago

I added explanation of paths with commit eaa54208c7fae058b6dc0ffc3311dd19438ad0cb. Can we close this?

khufkens commented 1 year ago

I would suggest to use the correct notation and terminology. Windows uses \ as directory separators instead of /. These are silently translated in R when using / (see normalizePaths()).

https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

You see this notation come back in for example our SMB Windows based network share: \giubstorage03.giub.unibe.ch\geco

If at all possible use pull request instead of commiting to the main branch, this causes merge conflicts.