Skip to content

Commit 4d7c79a

Browse files
committed
changed load and attach itnernals
1 parent bef34be commit 4d7c79a

File tree

2 files changed

+27
-51
lines changed

2 files changed

+27
-51
lines changed

R/internal.R

+26-51
Original file line numberDiff line numberDiff line change
@@ -107,42 +107,21 @@ out <- function(input, type = 1, ll = NULL, msg = FALSE, sign = "", verbose = ge
107107
return(y)
108108
}
109109

110-
# #' @importFrom sf st_crs st_set_crs
111-
# #' @importFrom stars read_stars st_set_dimensions
112-
# #'
113-
# #' @keywords internal
114-
# #' @noRd
115-
# .dc_query <- function(dc, query, method = "find_datasets", return_class = "stars"){
116-
#
117-
# if(!any(grepl("datacube.api.core.Datacube", class(dc)))){
118-
# out("'dc' must be of class 'datacube...'.", type = 3)
119-
# }
120-
#
121-
# # load: query and subsetting done by datacube
122-
# if(method == "load"){
123-
# ds <- do.call(dc$load, query)
124-
#
125-
# # return xarray python object
126-
# if(return_class == "xarray"){
127-
# return(ds)
128-
# }
129-
#
130-
# # return converted stars object
131-
# if(return_class == "stars"){
132-
# .xarray_convert(ds)
133-
# }
134-
# }
135-
#
136-
# # find_datasets: create a proxy/vrt stack instead of loading
137-
# if(method == "find_datasets"){
138-
#
139-
# # get paths
140-
# dc_find_datasets(dc, query)
141-
#
142-
# ###### ADD METHOD TO DEAL WITH PATHS HERE #######
143-
#
144-
# }
145-
# }
110+
#' @importFrom reticulate import
111+
#' @keywords internal
112+
#' @noRd
113+
.dc_available <- function(){
114+
dc <- try(import("datacube"), silent = T)
115+
if(inherits(dc, "try-error")) FALSE else TRUE
116+
}
117+
118+
#' @importFrom reticulate import
119+
#' @keywords internal
120+
#' @noRd
121+
.dc_version <- function(){
122+
dc <- try(import("datacube"), silent = T)
123+
if(!inherits(dc, "try-error")) dc$"__version__" else ""
124+
}
146125

147126
# global reference to datacube
148127
datacube <- NULL
@@ -153,27 +132,23 @@ np <- NULL
153132
#' @keywords internal
154133
#' @noRd
155134
.onLoad <- function(libname, pkgname) {
135+
Sys.setenv(RETICULATE_MINICONDA_ENABLED=FALSE)
136+
156137
# use superassignment to update global references
157-
datacube <<- import("datacube", delay_load = TRUE)
158-
np <<- import("numpy", delay_load = TRUE)
138+
datacube <<- reticulate::import("datacube", delay_load = TRUE)
139+
np <<- reticulate::import("numpy", delay_load = TRUE)
159140

160141
options(odcr.dc = NA)
161142
options(odcr.verbose = TRUE)
143+
}
162144

163-
dc <- try(import("datacube"), silent = T)
164-
if(inherits(dc, "try-error")){
165-
m <- "Could not auto-link to datacube, please use odcr::config() to link to the correct python binary/environment that has the datacube module installed."
145+
#' @keywords internal
146+
#' @noRd
147+
.onAttach = function(libname, pkgname) {
148+
if(.dc_available()){
149+
m <- paste0("Linking to datacube ", .dc_version())
166150
} else{
167-
v <- dc$"__version__"
168-
m <- paste0("Linking to datacube ", v)
151+
m <- "Could not auto-link to datacube, please use odcr::config() to link to the correct python binary/environment that has the datacube module installed."
169152
}
170-
171-
# if(!py_module_available("datacube")){
172-
# m <- "Could not auto-link to datacube, please use odcr::config() to link to the correct python binary/environment that has the datacube module installed."
173-
# } else{
174-
# #v <- datacube$"__version__"
175-
# m <- paste0("Linking to datacube") # ", v)
176-
# }
177-
178153
packageStartupMessage(m)
179154
}

odcr.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ StripTrailingWhitespace: Yes
1818
BuildType: Package
1919
PackageUseDevtools: Yes
2020
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageCheckArgs: --as-cran
2122
PackageRoxygenize: rd,collate,namespace

0 commit comments

Comments
 (0)