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 94a5a15..27103e9 100644 --- a/R/deepforestr.R +++ b/R/deepforestr.R @@ -1,9 +1,36 @@ +#' 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 #' #' @examples +#' \dontrun{ #' deepforestr::get_data("OSBS_029.png") +#' } #' #' @importFrom reticulate import r_to_py #' @export @@ -12,10 +39,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/README.md b/README.md index 761772a..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')) # 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/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") +} } 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()} + +}