connectwidgets icon indicating copy to clipboard operation
connectwidgets copied to clipboard

Top level tag missing?

Open iainmwallace opened this issue 3 years ago • 1 comments

Is it possible to retrieve the top level of a tag hierarchy? The tags function doesn't seem to return it.

For example if I have

Project

  • Project1
  • Project2

The tag function will only show project1 and project2 not Project

Thanks

Iain

iainmwallace avatar Apr 20 '22 23:04 iainmwallace

Posting the function I wrote to make a tag, with hierarchy, variable in the tag data. This may be useful if there is a desire to implement something similar.

get_tag_data_with_hierarchy <- function(client, sep = "/") {
  tag_data <- connectapi::get_tag_data(client)

  tag_data$name_hierarchy <- purrr::map_chr(
    tag_data$id,
    function(xx) {
      pop_dat <- tag_data[tag_data$id == xx, ]
      tmp_out <- pop_dat$name
      # checking for multiple tag levels
      while (!is.na(pop_dat$parent_id)) {
        tmp_out <- glue::glue(
          "{tag_data$name[tag_data$id == pop_dat$parent_id]}{sep}{tmp_out}"
        )
        pop_dat <- tag_data[tag_data$id == pop_dat$parent_id, ]
      }
      tmp_out
    }
  )
  tag_data
}

wfulp avatar Jun 23 '22 15:06 wfulp