henrykironde / rdataretriever

R interface to the Data Retriever
Other
0 stars 0 forks source link

notes #5

Open henrykironde opened 5 years ago

henrykironde commented 5 years ago

https://cran.r-project.org/web/packages/reticulate/vignettes/calling_python.html

henrykironde commented 5 years ago
library(reticulate)
check__import = function(){
  # Check if reticulate can import retriever
  tryCatch(
    {imported_retriever = reticulate::import('PyMySQL')},
    error=function(error_message) {
      message("The python module retriever was not found")
      message("Full error trace:")
      message(error_message)
      return(NA)
    }
  )
}
check__import()
getwd()
setwd("~/Documents/GitHub/rdataretriever")

install.packages(".", repos = NULL, type="source", quiet = FALSE, verbose = TRUE)
devtools::check()
roxygen2::roxygenise()
devtools::test()
devtools::check(force_suggests = FALSE)
install.packages(".", repos = NULL, type="source")
roxygen2::roxygenise()
install.packages(".", repos = NULL, type="source")
devtools::check(force_suggests = FALSE)
devtools:document()
devtools::document()
install.packages(".", repos = NULL, type="source")
devtools::check(force_suggests = FALSE)
install.packages(".", repos = NULL, type="source")
devtools::check(force_suggests = FALSE)
install.packages(".", repos = NULL, type="source")
devtools::check(force_suggests = FALSE)

library(reticulate)
install.packages("DBI")
install.packages("RPostgreSQL")
install.packages("RSQLite")
install.packages("reticulate")
install.packages("devtools")
library(devtools)
library(DBI)
library(RPostgreSQL)
library(RSQLite)
library(reticulate)
library(devtools)
install.packages(".", repos = NULL, type="source")
devtools::test()
print(sessionInfo())
devtools::check(force_suggests = FALSE)
update.packages(ask = FALSE, checkBuilt = TRUE)
library(reticulate)
library(DBI)
devtools::check()
devtools::test()
devtools::test()
install.packages(".", repos = NULL, type="source")
devtools::check()
setwd("~/Documents/GitHub/rdataretriever")
library(devtools)
install.packages(".", repos = NULL, type="source", deps=TRUE)
devtools::test()
remove.packages('rdataretriever')
remove.packages('reticulate')
print(sessionInfo())
installed.packages()
library(installr)
updateR()
install.packages(pacman)
d = c()
m = reticulate::r_to_py(d)
reticulate::py_to_r(c=list())

g = list()
m = reticulate::r_to_py(g)
rdataretriever::install_postgres("harvard-forest")
# retriever install postgres usgs-elevation -b list(-94.98704597353938, 39.027001800158615, -94.3599408119917, 40.69577051867074)
rdataretriever::install_postgres('usgs-elevation', list(-94.98704597353938, 39.027001800158615, -94.3599408119917, 40.69577051867074))
rdataretriever::install_postgres('harvard-forest')
rdataretriever::install_postgres('bioclim', )
rdataretriever::install_postgres("harvard-forest", host="pgdb", database="testdb")
# retriever install postgres usgs-elevation -b -94.98704597353938 39.027001800158615 -94.3599408119917 40.69577051867074
# retriever install postgres harvard-forest
# retriever install postgres bioclim

install_postgres = function(dataset, user='postgres', password='', host='localhost',
                            port=5432, database='postgres',
                            database_name='{db}', table_name='{db}.{table}', bbox=list(),
                            debug=FALSE, use_cache=TRUE)
os_password = ''
pgdb <- "localhost"
mysqldb <- "localhost"
doker_or_travis <- Sys.getenv("TRAVIS_OR_DOCKER")
# Check if  environment variable "TRAVIS_OR_DOCKER" was set to "true"
if (doker_or_travis != "doker_or_travis") 
  os_password = 'Password12!'
  pgdb = "pgdb"
  mysqldb = "mysqldb"
check_for_retriever = function(...) {
  python_paths_found = py_config()[13][[1]]
  unique_python_paths = unique(unlist(lapply(python_paths_found,dirname)))
  normalized_python_paths = unlist(lapply(unique_python_paths, normalizePath))
  compile_path = paste(normalized_python_paths,collapse = ':')
  # Export the detected paths
  Sys.setenv(PATH = paste(python_paths,':',Sys.getenv('PATH'),sep=''))

  retriever_path = Sys.which('retriever')
  if (retriever_path == '') {
    path_warn = 'The retriever is not on your path and may not be installed.'
    mac_instr = 'Follow the instructions for installing and manually adding the Data Retriever to your path at http://www.data-retriever.org/#install'
    download_instr = 'Please upgrade to the most recent version of the Data Retriever, which will automatically add itself to the path http://www.data-retriever.org/#install'
    os = Sys.info()[['sysname']]
    if (os == 'Darwin')
      packageStartupMessage(paste(path_warn, mac_instr))
    else
      packageStartupMessage(paste(path_warn, download_instr))
    }
}
henrykironde commented 5 years ago

install.packages("DBI") install.packages("RPostgreSQL") install.packages("RSQLite") install.packages("reticulate") install.packages("devtools") library(devtools) library(DBI) library(RPostgreSQL) library(RSQLite) library(reticulate) library(devtools) install.packages(".", repos = NULL, type="source") devtools::test()

henrykironde commented 5 years ago

Or run rdataretriver::get_updates() to get the newest available datasets

henrykironde commented 3 years ago

devtools::install_local(".")