Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Investigate diff between sb_replace_files() and sb_replace_files_log() #6

@msleckman

Description

@msleckman

There is some confusion around the existence and versioning of sb_replace_files_log() and sb_replace_files() in the src/sb_utiles.R of this template repo.

Couples thoughts and discussion questions:

-sb_replace_files_log() in this hierarchical data release repo is identical to the sb_replace_files() function that is in the slim-data-release src/sb_utils.R and this function was used in recently published data release repos (drb-temp-v2, @padilla410's lake-temp data release repo).

To align with slim-data-release-template and recent data releases, I've renamed this repo's sb_replace_files_log() --> sb_replace_files() (commit edd6df0 PR #9), and this repo's sb_replace_files() --> sb_replace_files_old().

  • sb_replace_files() vs. _old:
    [1]
sb_replace_files <- function(filename, sb_id, ..., file_hash, sources = c()){
  files <- c(...)
  if (!missing(file_hash)){
    files <- c(files, names(yaml.load_file(file_hash))) %>% sort() 
  }

  # Throw error if there are no files given to push
  stopifnot(length(files) > 0)
  do_item_replace_tasks(sb_id, files, sources) %>% 
    write_csv(filename)
}
  • The old version includes several additional lines of codes, and conditional statements such as checking the dssecrets authentication:
    [2]
sb_replace_files_old <- function(sb_id, ..., file_hash){ 
  if (!sbtools::is_logged_in()){ 
    sb_secret <- dssecrets::get_dssecret("cidamanager-sb-srvc-acct")
    sbtools::authenticate_sb(username = sb_secret$username, password = sb_secret$password)   
  } 
  hashed_filenames <- c()
  if (!missing(file_hash)){
    hashed_filenames <- yaml.load_file(file_hash) %>% names %>% sort() %>% rev()
    for (file in hashed_filenames){
      item_replace_files(sb_id, files = file)
    }
  }
  files <- c(...)
  if (length(files) > 0){
    item_replace_files(sb_id, files = files)
  }
}

@limnoliver, if you know, can you share why this function was updated to the one above [1] ? Are there any elements of this old function [2] that are worth keeping (e.g. should we be checking the sb authentication status in sb_replace_files()) ? Can I delete this function code entirely?

@jesse-ross,:

  • Surprisingly, this function sb_replace_files_old() works for making changes on a sciencebase locally, but does not work when using it in an interactive R console in Caldera. Might you know why this is?
  • sb_replace_files() works with Caldera (and locally), but I must run authenticate_sb() in the console in order for it to work.
  • How can we make sure dssecrets is up to date in the appropriate repos in the iidd/data_releases/ in caldera?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions