R/zzz.R

Defines functions ee_py_to_r ee_reattach .onAttach .onLoad

Documented in ee_py_to_r ee_reattach

.onLoad <- function(libname, pkgname) {
  # use superassignment to update global reference
  ee <<- reticulate::import("ee", delay_load = TRUE)
}

.onAttach <- function(libname, pkgname) {
  #packageStartupMessage(
  #"ee is a reserved word for the rgee package, try ee_restart() to reattach")
  options(rgee.print.option = "simply")
  #options(rgee.upload.properties = list(time_start="1970-01-01",
  #                                      time_end="1970-01-01"))
}

#' Reattach ee as a reserved word
#' @export
ee_reattach <- function() {
  ee <<- reticulate::import("ee", delay_load = TRUE)
}

#' Convert between Python and R objects
#' @param x A python object
#' @export
ee_py_to_r <- function(x) {
  p_r <- suppressWarnings(try(py_to_r(x),silent = TRUE))
  if (class(p_r) %in% 'try-error') {
    return(x)
  } else {
    return(p_r)
  }
}
ryali93/rgee documentation built on May 13, 2020, 4:34 a.m.