@@ -30,7 +30,7 @@ get_tskit_py <- function(object_name = "tskit") {
3030 if (test ) {
3131 tskit <- get(object_name , envir = .GlobalEnv , inherits = FALSE )
3232 test <- reticulate :: is_py_object(tskit ) &&
33- is(tskit ) == " python.builtin.module"
33+ is(tskit , " python.builtin.module" )
3434 if (test ) {
3535 return (tskit )
3636 } else {
@@ -43,22 +43,36 @@ get_tskit_py <- function(object_name = "tskit") {
4343 }
4444 }
4545 # else
46- # These lines are hard to hit with tests with cached reticulate Python and modules
46+ # These lines are hard to hit with tests and cached reticulate Python and modules
4747 # nocov start
48+ msgSuccess <- ' reticulate::py_require("tskit") succeded!'
49+ msgFail <- ' reticulate::py_require("tskit") failed!'
50+ e <- simpleError(msgFail )
4851 if (! reticulate :: py_module_available(" tskit" )) {
4952 txt <- " Python module 'tskit' is not available. Attempting to install it ..."
5053 message(txt )
51- reticulate :: py_require(" tskit" )
54+ out <- tryCatch(
55+ reticulate :: py_require(" tskit" ),
56+ error = function (s ) e
57+ )
58+ if (is(out , " simpleError" )) {
59+ return (msgFail )
60+ }
5261 }
53- # nocov end
54- return (reticulate :: import(" tskit" , delay_load = TRUE ))
62+ msgFail <- ' reticulate::import("tskit") failed!'
63+ e <- simpleError(msgFail )
64+ out <- tryCatch(
65+ reticulate :: import(" tskit" , delay_load = TRUE ),
66+ error = function (e ) e
67+ )
68+ return (out )
5569}
5670
5771# ' @describeIn get_tskit_py Test if \code{get_tskit_py} returned a reticulate Python module object
5872# ' @export
5973check_tskit_py <- function (object , stop = FALSE ) {
6074 test <- reticulate :: is_py_object(object ) &&
61- (" python.builtin.module" %in% is( object ))
75+ (is( object , " python.builtin.module" ))
6276 if (test ) {
6377 return (TRUE )
6478 } else {
0 commit comments