Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy tutorial folder to temp folder when calling run_tutorial #347

Closed
schloerke opened this issue Apr 7, 2020 · 7 comments · Fixed by #412
Closed

Copy tutorial folder to temp folder when calling run_tutorial #347

schloerke opened this issue Apr 7, 2020 · 7 comments · Fixed by #412
Labels
difficulty: intermediate Enterprising community members could help effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code
Milestone

Comments

@schloerke
Copy link
Collaborator

See rstudio/rstudio#6583

Paraphrasing...

learnr attempts to render the learnr document directly in the installed package's folder. We need to check for write permissions and instead copy + run within the R temporary directory (since learnr + learnr-using packages might be installed into an R library that the running user doesn't have write access to)

cc @kevinushey @trestletech

@schloerke schloerke added difficulty: intermediate Enterprising community members could help effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code labels Apr 7, 2020
bhogan-mitre added a commit to bhogan-mitre/learnr that referenced this issue Jun 4, 2020
@bhogan-mitre
Copy link

Could this be as simple as passing render_args <- list(output_dir = tempdir()) as argument to rmarkdown::run?

Here's a commit that does that.

For example, with run_tutorial("slidy", "learnr"), that produces:

Output created: /tmp/RtmpYSUQAT/slidy.html

@bhogan-mitre
Copy link

Actually this needs a bit more work in the intended environment (system library with unprivileged user).

Error in file(con, "w") : cannot open the connection In addition: Warning message: In file(con, "w") : cannot open file 'slidy.knit.md': Permission denied

I will try to clean it up and submit a PR if I can confirm it's working properly.

@bhogan-mitre
Copy link

Okay, I did get this to work as intended as an unprivileged user with learnr in the system library.

processing file: slidy.Rmd
...

output file: /tmp/RtmpOj37CC/slidy.knit.md
...

Output created: /tmp/RtmpOj37CC/slidy.html

PR forthcoming with the patch, if you're open to it. Thanks in advance for considering.

@schloerke
Copy link
Collaborator Author

@bhogan-mitre Thank you for looking into this error!

One thing that we will want to try to do is maintain the current save location as it will exist after R shuts down / computer restart. By always storing it as a temp file, then a lot of shiny-prerendered functionality is turned into a standard Rmd file.

If we could check that we have write privileges in the expected location, we should leave the Rmd output as is. If we do not have write privileges, setting the output to a temp dir is a great solution.

PRs are always welcome!!

@jcheng5
Copy link
Member

jcheng5 commented Jun 10, 2020

Hmmm, is it ever a good idea to write into a package library (other than, like, actually installing/updating/removing a package)? Seems wrong somehow!

@homerhanumat
Copy link

How is this coming along? (For now I suppose just ask students to install the tutorial-endowed package into their User Library and use learnr:run_tutorial() in the Console.)

@schloerke schloerke added this to the v0.11.0 milestone Jun 15, 2020
@schloerke
Copy link
Collaborator Author

schloerke commented Jun 15, 2020

@homerhanumat Unfortunately stalled for the moment.


Update on approach: Use a cache disk location and copy the tutorial directory, then compile in there.

Ex tutorial directory: file.path(rappdirs::user_data_dir(), "R", "learnr", "tutorial", "package") similar to

file.path(rappdirs::user_data_dir(), "R", "learnr", "tutorial", "storage")
with the file location being something like

`rappdirs::user_data_dir()`/R/learnr/tutorial/package/learnr/hello/*

This would allow for tutorial output to persist between R sessions and not build them in the installed folder.

This cache folder could be checked for being able to write and could failover to the temp folder.

arthurian added a commit to fasrc/fas-ondemand-rstudio that referenced this issue Jan 19, 2021
Tutorials will not run when they are installed system-wide due to the
fact that they are trying to write intermediate files to a read-only
package directory. The latest source release fixes this by writing
intermediate files to a temp directory.

See also: rstudio/learnr#347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: intermediate Enterprising community members could help effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code
Projects
None yet
4 participants