From dd284f0d7a2f4671a2efd0e58f25837455e03dbb Mon Sep 17 00:00:00 2001 From: Ethan White Date: Sun, 14 Jul 2024 12:28:12 -0400 Subject: [PATCH 1/3] Force the use of conda in install instructions This avoids virtualenv being selected causing issues with geospatial installs. Addresses issues like those in #12. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 761772a..bbfc069 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If installing on Windows you need to [install RTools](https://cran.r-project.org ```R install.packages('reticulate') # Install R package for interacting with Python reticulate::install_miniconda() # Install Python -reticulate::py_install(c('gdal', 'rasterio', 'fiona')) # Install spatial dependencies via conda +reticulate::py_install(c('gdal', 'rasterio', 'fiona'), method='conda') # Install spatial dependencies via conda reticulate::conda_remove('r-reticulate', packages = c('mkl')) # Remove package that causes conflicts on Windows (and maybe macOS) reticulate::py_install('DeepForest', pip=TRUE) # Install the Python retriever package devtools::install_github('weecology/deepforestr') # Install the R package for running the retriever From 197d357524fdf0da60110b43be9d7d6c209d1aaf Mon Sep 17 00:00:00 2001 From: Ethan White Date: Wed, 17 Jul 2024 22:05:02 -0400 Subject: [PATCH 2/3] Don't run examples since they require deepforest --- R/deepforestr.R | 9 ++++++--- man/df_model.Rd | 5 +++-- man/get_data.Rd | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/R/deepforestr.R b/R/deepforestr.R index 94a5a15..a28ef0b 100644 --- a/R/deepforestr.R +++ b/R/deepforestr.R @@ -3,7 +3,9 @@ #' @param path path to the example data file #' #' @examples +#' \dontrun{ #' deepforestr::get_data("OSBS_029.png") +#' } #' #' @importFrom reticulate import r_to_py #' @export @@ -12,10 +14,11 @@ get_data <- function(path) { } #' Deepforest Model object -#' -#' @examples -#' deepforestr::df_model() #' +#' @examples +#' \dontrun{ +#' model = deepforestr::df_model() +#' } #' @importFrom reticulate import r_to_py #' @export df_model <- function() { diff --git a/man/df_model.Rd b/man/df_model.Rd index f757a3c..b41306d 100644 --- a/man/df_model.Rd +++ b/man/df_model.Rd @@ -10,6 +10,7 @@ df_model() Deepforest Model object } \examples{ -deepforestr::df_model() - +\dontrun{ +model = deepforestr::df_model() +} } diff --git a/man/get_data.Rd b/man/get_data.Rd index 54a1ea4..da2e189 100644 --- a/man/get_data.Rd +++ b/man/get_data.Rd @@ -13,6 +13,8 @@ get_data(path) Get example data } \examples{ +\dontrun{ deepforestr::get_data("OSBS_029.png") +} } From 12d9053d8028c50f159a71d98abfdc8da2bc811e Mon Sep 17 00:00:00 2001 From: Ethan White Date: Wed, 17 Jul 2024 22:07:04 -0400 Subject: [PATCH 3/3] Create a function to run install steps This simplifies the install of external dependencies following packages like cmdstanr. --- DESCRIPTION | 3 ++- NAMESPACE | 4 ++++ R/deepforestr.R | 25 +++++++++++++++++++++++++ README.md | 9 ++------- man/install_deepforest.Rd | 16 ++++++++++++++++ 5 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 man/install_deepforest.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d590c18..917d94d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,10 +24,11 @@ Suggests: testthat (>= 1.0.0), devtools, knitr, + raster, rmarkdown VignetteBuilder: knitr SystemRequirements: Python (>= 3.0) (version must be listed to patch to allow parsing) License: MIT + file LICENSE LazyData: true -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 18123e4..92d347b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,5 +2,9 @@ export(df_model) export(get_data) +export(install_deepforest) +importFrom(reticulate,conda_remove) importFrom(reticulate,import) +importFrom(reticulate,install_miniconda) +importFrom(reticulate,py_install) importFrom(reticulate,r_to_py) diff --git a/R/deepforestr.R b/R/deepforestr.R index a28ef0b..27103e9 100644 --- a/R/deepforestr.R +++ b/R/deepforestr.R @@ -1,3 +1,28 @@ +#' Install the DeepForest Python package +#' +#' @examples +#' \dontrun{ +#' deepforestr::install_deepforest()} +#' +#' @importFrom reticulate install_miniconda py_install conda_remove +#' @export +install_deepforest <- function() { + miniconda_path = reticulate::miniconda_path() + if (!dir.exists(miniconda_path)) { + reticulate::install_miniconda() + } else { + print(sprintf("Using existing miniconda install at %s", miniconda_path)) + } + reticulate::py_install(c("gdal", "rasterio", "fiona"), method = "conda") + #if (reticulate::py_module_available("mkl")) { + # Remove package that has caused conflicts on Windows due to double install + # The correct version of mkl will be installed with deepforest (below) + # on systems where it is needed + # reticulate::conda_remove("r-reticulate", packages = c("mkl")) + #} + reticulate::py_install("DeepForest", method = "conda", pip = TRUE) +} + #' Get example data #' #' @param path path to the example data file diff --git a/README.md b/README.md index bbfc069..709fe08 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,8 @@ This will create a local Python installation that will only be used by R and ins If installing on Windows you need to [install RTools](https://cran.r-project.org/bin/windows/Rtools/) before installing the R package. ```R -install.packages('reticulate') # Install R package for interacting with Python -reticulate::install_miniconda() # Install Python -reticulate::py_install(c('gdal', 'rasterio', 'fiona'), method='conda') # Install spatial dependencies via conda -reticulate::conda_remove('r-reticulate', packages = c('mkl')) # Remove package that causes conflicts on Windows (and maybe macOS) -reticulate::py_install('DeepForest', pip=TRUE) # Install the Python retriever package -devtools::install_github('weecology/deepforestr') # Install the R package for running the retriever -install.packages('raster') # For visualizing output for rasters +devtools::install_github('weecology/deepforestr') # Install the R package from GitHub +deepforestr::install_deepforest() # Install Python & DeepForest; Takes ~3 minutes ``` **After running these commands restart R.** diff --git a/man/install_deepforest.Rd b/man/install_deepforest.Rd new file mode 100644 index 0000000..9429308 --- /dev/null +++ b/man/install_deepforest.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deepforestr.R +\name{install_deepforest} +\alias{install_deepforest} +\title{Install the DeepForest Python package} +\usage{ +install_deepforest() +} +\description{ +Install the DeepForest Python package +} +\examples{ +\dontrun{ +deepforestr::install_deepforest()} + +}