From c1ad501ee46b252e23b72b4a10f424e199a9f191 Mon Sep 17 00:00:00 2001 From: aheinri5 <Anna@netzkritzler.de> Date: Sat, 16 Jan 2021 22:03:17 +0100 Subject: [PATCH] [base] Added delay_load flags for python libraries to zzz.R --- R/zzz.R | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 0ae89a4..6cf2d9a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,23 +1,64 @@ + +# global Python references (will be initialized in .onLoad) +vtk <- NULL +zlib <- NULL + + .onLoad <- function(libname, pkgname){ op <- options() op.r2ogs6 <- list( # Default paths - r2ogs6.default_sim_path = "D:/OGS_sims/", - r2ogs6.default_script_path = "D:/OGS_scripts/", - r2ogs6.default_benchmark_path = - "D:/Programme/OpenGeoSys/ogs-master-Tests-Data/Tests/Data/", - r2ogs6.default_ogs_bin_path = - paste0("D:/Programme/OpenGeoSys/", - "ogs-6.3.2-Windows-10.0.14393-x64-python-3.7.2-de-utils", - "/bin/") + r2ogs6.default_sim_path = "", + r2ogs6.default_script_path = "", + r2ogs6.default_benchmark_path = "", + r2ogs6.default_ogs_bin_path = "", + r2ogs6.max_lines_gml = 300, # External file reference tags + + # Reticulate setting for reading in VTK + r2ogs6.use_python = "" ) + toset <- !(names(op.r2ogs6) %in% names(op)) if (any(toset)) options(op.r2ogs6[toset]) + # use superassignments to update global Python references + vtk <<- reticulate::import("vtk", delay_load = TRUE) + vtk_dsa <<- reticulate::import("vtk.numpy_interface.dataset_adapter", + delay_load = TRUE) + zlib <<- reticulate::import("zlib", delay_load = TRUE) + + test_config <- TRUE + + if (test_config) { + options( + r2ogs6.default_sim_path = "D:/OGS_sims/", + r2ogs6.default_script_path = "D:/OGS_scripts/", + r2ogs6.default_benchmark_path = + "D:/Programme/OpenGeoSys/ogs-master-Tests-Data/", + r2ogs6.default_ogs_bin_path = + paste0( + "D:/Programme/OpenGeoSys/", + "ogs-6.3.2-Windows-10.0.14393-x64-python-3.7.2-de-utils", + "/bin/" + ), + r2ogs6.use_python = "D:/Programme/anaconda3/envs/rtest/python.exe", + r2ogs6.max_lines_gml = 300 + ) + + reticulate::use_virtualenv(unlist(options("r2ogs6.use_python"))) + } + cat("Loaded package r2ogs6. Your options are set as follows:\n\n", + paste( + names(options()[grepl("r2ogs6.", names(options()), fixed = TRUE)]), + options()[grepl("r2ogs6.", names(options()), fixed = TRUE)], + sep = " = ", + collapse = "\n"), + "\n\nTo change them, type options(\"<option_name>\" = <option_value>).", + sep = "") invisible() } \ No newline at end of file -- GitLab