rstudio/pygradethis

Safer loading when python or pygradethis python package aren't available

Closed this issue · 0 comments

I think we should rethink this .onLoad() code, either to make it safer (don't fail and emit a warning about missing pygradethis) or do it somewhere else (a package hook for when learnr is loaded?).

pygradethis/R/R/zzz.R

Lines 20 to 25 in 7afd7fd

.onLoad <- function(libname, pkgname) {
# import `pygradethis` and the exercise checking function
pygradethis <<- reticulate::import("pygradethis", convert=FALSE, delay_load = TRUE)
pygradethis_exercise_checker <<- pygradethis$pygradethis_exercise_checker$pygradethis_exercise_checker
get_last_value <<- pygradethis$utils$get_last_value
}

The problem is that it is now fully blocking — you can't work in a project that requires the pygradethis R package without installing or resolving Python issues. This is because R's package installation checks test that pygradethis can load and if Python isn't installed the check fails and pygradethis fails to be installed.

Installing pygradethis [0.0.0.9000] ...
	FAILED
Error installing package 'pygradethis':
=======================================

* installing to library ‘/mnt/home/garrick/academyContent/renv/staging/1’
* installing *source* package ‘pygradethis’ ...
** using staged installation
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘pygradethis’:
 .onLoad failed in loadNamespace() for 'pygradethis', details:
  call: NULL
  error: Python module pygradethis was not found.