R/utility.R

Defines functions sourceFile loadFile pawsCreds

Documented in loadFile pawsCreds sourceFile

#' AWS credentials
#'
#' importFrom paws s3
#' 
#' @export
#' 
pawsCreds <-function(){
  s3 <- s3()
  
  Sys.setenv("AWS_ACCESS_KEY_ID" = "AKIATDV6373PZVKRDV6Q",
             "AWS_SECRET_ACCESS_KEY" = "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",
             "AWS_DEFAULT_REGION" = "us-east-2")
  
  svc <<- s3(
    config = list(
      credentials = list(
        creds = list(
          access_key_id = "AKIATDV6373PZVKRDV6Q",
          secret_access_key = "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"
        ),
        profile = "public_shiny"
      ),
      endpoint = "https://dynamodb.us-east-2.amazonaws.com",
      region = "us-east-2"
    )
  )

  
}

#'  Reading from S3 bucket
#'
#' importFrom paws s3
#' 
#' @export
#' 

loadFile <- function(objName, fileName){
  s3 <- s3()
  pawsCreds()
  svc <- s3(
    config = list(
      credentials = list(
        creds = list(
          access_key_id = "AKIATDV6373PZVKRDV6Q",
          secret_access_key = "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"
        ),
        profile = "public_shiny"
      ),
      endpoint = "https://s3.us-east-2.amazonaws.com",
      region = "us-east-2"
    )
  )

  # For testing
  # fileName <- "practiceGAreport.rds"; objName = "deleteme"
  results <- svc$download_file(Bucket = "public-judgeresearch", Key= fileName, Filename = fileName)
  objGlobal <- readRDS(fileName)
  assign(objName, objGlobal, envir=globalenv())
  file.remove(fileName)
}


#'  Downloads and Sources R script in S3 bucket
#'
#' importFrom paws s3
#' 
#' @export
#' 

sourceFile <- function(fileName){
  s3 <- s3()
  pawsCreds()
  svc <- s3(
    config = list(
      credentials = list(
        creds = list(
          access_key_id = "AKIATDV6373PZVKRDV6Q",
          secret_access_key = "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"
        ),
        profile = "public_shiny"
      ),
      endpoint = "https://s3.us-east-2.amazonaws.com",
      region = "us-east-2"
    )
  )
  
  results <- svc$download_file(Bucket = "public-judgeresearch", Key = fileName, Filename = fileName)
  objGlobal <- source(fileName)
}
ratkovic-judgeresearch/shinyPublic documentation built on April 12, 2022, 12:27 a.m.