Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve installation experience #18

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
34 changes: 31 additions & 3 deletions R/deepforestr.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
5 changes: 3 additions & 2 deletions man/df_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/get_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/install_deepforest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading