Skip to content

Allow data-entry updating utility functions? #38

@jfy133

Description

@jfy133

I'm finally getting a little bit back into using pandora/sidora again, and I have just written a little function that allows you to add new tags to entries (which you could then use with format_as_update_existing(), to save a file for the whole Pandora uploading thing).

add_new_tags <- function(old_tags, new_tags){
  old_tags <- str_split(old_tags, ",")
  new_tags <- str_split(new_tags, ",")
  
  append(old_tags, new_tags) %>% unlist %>% sort %>% unique %>% paste0(collapse = ",") %>% gsub("^,", "", .)
}

This brought up a question in my mind as whether we should provide 'modification' functions or not, and if yes, to what extent?

Thoughts @sidora-tools/core?

Also @ivelsko would this be a sort of thing you would be interested in?

A more detailed example:

library(dplyr)

add_new_tags <- function(old_tags, new_tags){
  old_tags <- str_split(old_tags, ",")
  new_tags <- str_split(new_tags, ",")
  
  append(old_tags, new_tags) %>% unlist %>% sort %>% unique %>% paste0(collapse = ",") %>% gsub("^,", "", .)
}


samples <- get_df("TAB_Sample", con)

# filter
samples_raw <- samples %>%
  filter(grepl("^ALA", sample.Full_Sample_Id)) %>%
  convert_all_ids_to_values() %>%
  filter(sample.Type_Group == "Calculus")

# update tag and convert for update exisiting entries format
samples_updated <- samples_raw %>%
  mutate(sample.Tags = map2(sample.Tags, "FoodTransforms,James Fellows Yates", add_new_tags)) %>%
  sidora.core::format_as_update_existing()

#write_csv(samples_updated, "Sample.csv")

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions