-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
schuemie
committed
Oct 11, 2023
1 parent
3b06636
commit e768143
Showing
3 changed files
with
21 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
# Code to work around renv bugs relating to Python | ||
# Code to install Python dependencies. Does not use conda as it was throwing inexplicable errors | ||
|
||
# Install all required dependencies -------------------------------------------- | ||
packages <- c("scikit-survival","numpy","scipy","scikit-learn", "pandas","pydotplus","joblib", "sklearn-json") | ||
reticulate::conda_install( | ||
envname='base', | ||
packages = packages, | ||
forge = TRUE, | ||
pip = FALSE, | ||
pip_ignore_installed = TRUE, | ||
conda = "auto" | ||
) | ||
reticulate::conda_install( | ||
envname='r-reticulate', | ||
packages = packages, | ||
forge = TRUE, | ||
pip = FALSE, | ||
pip_ignore_installed = TRUE, | ||
conda = "auto" | ||
) | ||
reticulate::use_condaenv("base") | ||
torch::install_torch() | ||
reticulate::use_condaenv("r-reticulate") | ||
torch::install_torch() | ||
# Install packages needed by PatientLevelPrediction ---------------------------- | ||
PatientLevelPrediction::configurePython(envname = 'r-reticulate', envtype = "python") | ||
reticulate::use_virtualenv("r-reticulate") | ||
# Test: np <- reticulate::import('numpy') | ||
|
||
# Copy Python from global to renv ---------------------------------------------- | ||
# Packages needed by DeepPatientLevelPrediction -------------------------------- | ||
reticulate::py_install(c("polars", "tqdm", "connectorx", "scikit-learn", "pyarrow")) | ||
reticulate::py_install("torch") | ||
# Test: torch <- reticulate::import('torch') | ||
pyarrow <- reticulate::import('pyarrow') | ||
|
||
# Under some (poorly understood) circumstances, reticulate creates a duplicate | ||
# r-reticulate environment. Use this code to copy all libraries from the main one | ||
# to the new one: | ||
envs <- reticulate::conda_list() | ||
envs <- envs[envs$name == 'r-reticulate', ] | ||
message(sprintf("Good r-reticulate: %s", envs$python[1])) | ||
message(sprintf("Evil r-reticulate: %s", envs$python[2])) | ||
# TODO: this somehow creates a r-reticulate folder in the r-reticulate folder. Need to fix | ||
unlink(dirname(envs$python[2]), recursive = TRUE) | ||
dir.create(dirname(envs$python[2])) | ||
file.copy( | ||
from = dirname(envs$python[1]), | ||
to = dirname(envs$python[2]), | ||
recursive = TRUE | ||
) | ||
# reticulate::virtualenv_remove("r-reticulate") | ||
|
||
reticulate::virtualenv_list() | ||
reticulate::virtualenv_root() |