From 6bdb14f3a6b306039afcb7b9a75298b02aedfe10 Mon Sep 17 00:00:00 2001 From: James J Balamuta Date: Fri, 26 Jan 2024 20:05:28 -0800 Subject: [PATCH] Guard against the custom package not being available by first checking if the package is present and, then, loading it. --- _extensions/webr/qwebr-document-engine-initialization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_extensions/webr/qwebr-document-engine-initialization.js b/_extensions/webr/qwebr-document-engine-initialization.js index 9ff0fbd3..835367f8 100644 --- a/_extensions/webr/qwebr-document-engine-initialization.js +++ b/_extensions/webr/qwebr-document-engine-initialization.js @@ -5,7 +5,7 @@ async function qwebrInstallRPackage(packageName) { // Function to load a single package async function qwebrLoadRPackage(packageName) { - await mainWebR.evalRVoid(`library(${packageName});`); + await mainWebR.evalRVoid(`if(requireNamespace('${packageName}', quietly = TRUE)) { library(${packageName}); }`); } // Generic function to process R packages