michaelwiel / hacking_medphys_R_part2

R Version for https://github.com/rvbCMTS/EMP-News.git
https://charmingquark.at/db_R_tutorial.html
1 stars 1 forks source link

problem with rprojroot::find_rstudio_root_file() #6

Open michaelwiel opened 2 years ago

michaelwiel commented 2 years ago

If rmd is moved out of the working directory (same directory as Rproj-File) it does not help as intended -> setting the working directory in a code chunk only changes the wd in that specific code chunk -> to change for all code chunks one has to set the working directory in the setup chunk with: knitr::opts_knit$set(root.dir = dir_set) -> even if wd is changed for all chunks it is NOT changed for the code in the text (outside of the code chunks) -> since there are links to images,... the file then can not be rendered

I suggest we take out this part and explain in the text that it is important that the necessery files have to be in the correct positions...

fgardavaud commented 2 years ago

Hi, I don't know if I understand correctly the problem. I apply some changes in the code of db_R_tutorial.Rmd to avoid problem if :

I can generate without problem the .html. I propose you a pull request to implement my changes. If it's ok for we can implement that in the other .Rmd file. If it's not working, I agree with you to take out this part.

michaelwiel commented 2 years ago

HI! I will take a look at it during the next few days! Have a nice weekend! m*

Am Mi., 29. Juni 2022 um 13:44 Uhr schrieb Francois Gardavaud < @.***>:

Hi, I don't know if I understand correctly the problem. I apply some changes in the code of db_R_tutorial.Rmd to avoid problem if :

  • the .rmd file is not at the same path level that the data file. I can generate without problem the .html. I propose you a pull request to implement my changes. If it's ok for we can implement that in the other .Rmd file. If it's not working, I agree with you to take out this part.

— Reply to this email directly, view it on GitHub https://github.com/michaelwiel/hacking_medphys_R_part2/issues/6#issuecomment-1169880781, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXN3ZTI6JHEFWXDH7VVBDODVRQZKNANCNFSM5Z26W7WA . You are receiving this because you were assigned.Message ID: @.***>

-- DI Michael Wieland

Am Tabor 48/1/23 A-1020 Wien

t: +43 650 356 46 26 m: @.***

michaelwiel commented 2 years ago

Hi! I copied the code from your repo instead of merging because I worked on the file in the meantime...

It still doesn't work on my machine though when the rmd is not in the right position...

from the log:

File figures/files_pane.png not found in resource path
Fehler: pandoc document conversion failed with error 99

I think this happens because "opts_knit$set(root.dir = path_project)" can set the directory for ALL CODE CHUNKS when knitting but NOT outside of the chunks.

For the rendering of the html file knitr "looks" into the folder "figures" which is accessed relative to the location of the rmd. When the rmd is moved somewhere else without the folder "figures", the folder is not found. This happens because the images for the html are added with inline markdown code (not with code chunks), for example:

![RStudio Enviroment with Source and Files Panes](figures/files_pane.png)

The working directory for the inline code (outside of the code chunks) is not affected by "opts_knit$set(root.dir = path_project)".

fgardavaud commented 2 years ago

Hi Michael,

Indeed you're right but if you put the executable file (in our case the .rmd file) in the wrong or a weird path whatever the language used it will not work.

This page can explain of the path stuff : https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html

To prevent this behaviour your proposal (to write some advices about this) is a great idea. User don't have to move and change the structure of the folder without caution.

Best.

François Gardavaud, MPE

Medical imaging department - Tenon University Hopistal ISCD - ED SMAER - Jussieu - Sorbonne University

Tél : +33(0)1.56.01.64.35 4 Rue de la Chine 75970 Paris Cedex 20 FRANCE

My website : https://fgardavaud.github.io/

My Github and GitHubGist repos : https://github.com/fgardavaud https://gist.github.com/fgardavaud

Le 4 juil. 2022 à 00:03, Michael Wieland @.**@.>> a écrit :

Hi! It still doesn't work on my machine when the rmd is not in the right position...

from the log:

File figures/files_pane.png not found in resource path Fehler: pandoc document conversion failed with error 99

I think this happens because "opts_knit$set(root.dir = path_project)" can set the directory for ALL CODE CHUNKS when knitting but NOT outside of the chunks.

For the rendering of the html file knitr "looks" into the folder "figures" which is accessed relative to the location of the rmd. When the rmd is moved somewhere else without the folder "figures", the folder is not found. This happens because the images for the html are added with inline markdown code (not with code chunks), for example:

RStudio Enviroment with Source and Files Panes

The working directory for the inline code (outside of the code chunks) is not affected by "opts_knit$set(root.dir = path_project)".

— Reply to this email directly, view it on GitHubhttps://github.com/michaelwiel/hacking_medphys_R_part2/issues/6#issuecomment-1173179461, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AM6YYBENOTLOQWUBXCSCJNDVSIE27ANCNFSM5Z26W7WA. You are receiving this because you commented.Message ID: @.***>

michaelwiel commented 2 years ago

Hi! Thanks for checking it. I will rewrite that part of the tutorial with the feedback from Gavin... Have a good week! Regards, Michael

Am Di., 5. Juli 2022 um 11:52 Uhr schrieb Francois Gardavaud < @.***>:

Hi Michael,

Indeed you're right but if you put the executable file (in our case the .rmd file) in the wrong or a weird path whatever the language used it will not work.

This page can explain of the path stuff : https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html

To prevent this behaviour your proposal (to write some advices about this) is a great idea. User don't have to move and change the structure of the folder without caution.

Best.

François Gardavaud, MPE

Medical imaging department - Tenon University Hopistal ISCD - ED SMAER - Jussieu - Sorbonne University

Tél : +33(0)1.56.01.64.35 4 Rue de la Chine 75970 Paris Cedex 20 FRANCE

My website : https://fgardavaud.github.io/

My Github and GitHubGist repos : https://github.com/fgardavaud https://gist.github.com/fgardavaud

Le 4 juil. 2022 à 00:03, Michael Wieland @.**@.>> a écrit :

Hi! It still doesn't work on my machine when the rmd is not in the right position...

from the log:

File figures/files_pane.png not found in resource path Fehler: pandoc document conversion failed with error 99

I think this happens because "opts_knit$set(root.dir = path_project)" can set the directory for ALL CODE CHUNKS when knitting but NOT outside of the chunks.

For the rendering of the html file knitr "looks" into the folder "figures" which is accessed relative to the location of the rmd. When the rmd is moved somewhere else without the folder "figures", the folder is not found. This happens because the images for the html are added with inline markdown code (not with code chunks), for example:

RStudio Enviroment with Source and Files Panes

The working directory for the inline code (outside of the code chunks) is not affected by "opts_knit$set(root.dir = path_project)".

— Reply to this email directly, view it on GitHub< https://github.com/michaelwiel/hacking_medphys_R_part2/issues/6#issuecomment-1173179461>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/AM6YYBENOTLOQWUBXCSCJNDVSIE27ANCNFSM5Z26W7WA>.

You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/michaelwiel/hacking_medphys_R_part2/issues/6#issuecomment-1174861576, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXN3ZTJ6CRBL5TWMOXDDAI3VSQAV5ANCNFSM5Z26W7WA . You are receiving this because you were assigned.Message ID: @.***>

-- DI Michael Wieland

Am Tabor 48/1/23 A-1020 Wien

t: +43 650 356 46 26 m: @.***