testScript.R

# script to get things working, no real need to send to git
devtools::install_github("ropenscilabs/datastorr")
# generating the datastorr package script
``` {r echo=FALSE, results="asis"}
pkg <- datastorr::autogenerate(repo = 'JCur96/datastorr.test', read = 'read.csv', filename = 'WorkingSouthAmerica.csv')
writeLines(c("```r", pkg,  "```"))
# installing the lightweight package
devtools::install_github('JCur96/datastorr.test', force = TRUE)
devtools::install_github('JCur96/GeoSpatialEcology')
library(MRes)
library(GeoSpatialEcology)
library(tidyverse)
# some testing
df <- MRes::mydata('0.1.0')
GeoSpatialEcology::correctColName(df)
write.csv(mydata, 'WorkingSouthAmerica.csv')
MRes::updateVersion()
MRes::mydata_release('Fixed Col Name (now reads binomial!)', 'WorkingSouthAmerica.csv')

GeoSpatialEcology::removeNA(df)
GeoSpatialEcology::prepBinomial(df$binomial)


# useful stuff below plus some experimentation
# set up git authorisation as publisher
datastorr::datastorr_auth()
datastorr::setup_github_token() # follow instructions when prompted
# and set your own permissions scope


# testing out the datastorr functions to see if they work
MRes::mydata_release('First test release', 'WorkingSouthAmerica.csv')
MRes::mydata_versions(local = F)
d1 <- MRes::mydata('0.1.0')
# Do something to the data here
d <- d[1,]
# Overwrite the data because we dont want lots of simialr dfs I think
write.csv(d, 'WorkingSouthAmerica.csv')
# Edit DESCRIPTION version here, push all changes to git
# Then update the release to be associated with that push
MRes::mydata_release('Test update release', 'WorkingSouthAmerica.csv')
# Should be two versions here now
MRes::mydata_versions(local = F)
d2 <- MRes::mydata('0.1.1')
# Looks like it all works but fuck is that clunky as shit

MRes::mydata_versions()
MRes::mydata_version_current()





prepNHMData <- function(df) {
  # needs usr input, so probably a
  print(colnames(df)) # followed by a
  colToChange <- readline(prompt = 'please enter column index to rename to binomial: ')
  colToChange <- as.numeric(colToChange)
  colnames(df)[colToChange] <- 'binomial'
  df <- df %>% filter(Longitude !=is.na(Longitude)
                      & Locality != '' & Extent_km < 800 & binomial != '')
  df$binomial <- gsub(' ', '_', df$binomial)
  df <- st_as_sf(df, coords = c("Longitude", "Latitude"), crs = 4326)
  dfName <- readline(prompt = 'please enter your df name: ')
  assign(dfName,df,envir=.GlobalEnv)
}



# Function for updating version number more painlessly
# updateVersion <- function() {
#   verNum <- readline(prompt = 'please enter new version number: ') # gets new version number
#   verNum = paste('Version:', verNum) # Makes the line whole again
#   lines <- readLines('DESCRIPTION') # reads the lines of file
#   lines[4] <- sub('Version: .+', verNum, lines[4]) # replaces with updated Ver
#   Desc <- file('DESCRIPTION') # save lines as DESCRITPTION overwritting it
#   writeLines(lines, Desc)
#   close(Desc)
#
# }
updateVersion()







# its possible to set up a git auth token using the below if you've already made one
# GITHUB_PAT TOKEN IS a5f537f2bab62c40b766c47adda1adfdfb4a071f SAVED IN EDITED R ENVIRON
library(usethis)
usethis::edit_r_environ()
usethis::github_token()
Sys.getenv('GITHUB_PAT')
credential_helper_get()


# a5f537f2bab62c40b766c47adda1adfdfb4a071f an auth_token that didn't work for whatever reason
JCur96/datastorr.test documentation built on June 29, 2019, 7:31 p.m.