R/store_methods.R

store_session <- function(key, value, group, internal = F){
  if(!internal){
    opt_tag <- "store.rsession"
  }else{
    opt_tag <- "store.internal"
  }

  lex <- options(opt_tag)[[1]]
  if(is.null(lex)){
    lex <- list()
  }

  if(!missing(group)){

    key_in <- key
    value_in <- value

    lex_grp <- lex[[group]]

    if(is.null(lex_grp)){
      lex_grp <- list()
    }

    lex_grp[[key_in]] <- value_in
    key <- group
    value <- lex_grp

  }

  lex[[key]] <- value

  lex1 <- list(lex)
  names(lex1) <- opt_tag
  options(lex1)

  invisible()
}

store_local <- function(key, value, group, local_path){

  file_path <- get_local_file_path(group, local_path)

  file_path %>% dirname %>% dir.create( recursive = T, showWarnings = F)

  if(file.exists(file_path)){
    lex <- readRDS(file_path)
  }else{
    lex <- list()
  }


  if(is.null(lex)){
    lex <- list()
  }

  lex[[key]] <- value

  saveRDS(lex, file_path)

  invisible()

}
MadeInR/store documentation built on May 12, 2019, 8:41 a.m.