From 8c37aab6ce6fcfa6e6eab9b43cb472a8cdacf9c8 Mon Sep 17 00:00:00 2001 From: Kiweler Date: Fri, 5 Jul 2019 13:10:49 +0200 Subject: [PATCH] fs instead of pathological --- DESCRIPTION | 2 +- R/output_functions.R | 16 ++++++---------- vignettes/manipulate_term_match_table.Rmd | 11 +++++++++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9ca1207..6056e6b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,9 +20,9 @@ Imports: assertive.strings, assertive.types, dplyr, + fs, jsonlite, magrittr, - pathological, rlist, stringi, tidyr, diff --git a/R/output_functions.R b/R/output_functions.R index fc0a1f3..c75f12e 100644 --- a/R/output_functions.R +++ b/R/output_functions.R @@ -26,29 +26,25 @@ save_group_table <- function(groups_vector, output_path, group_number) { assertive.types::assert_is_list(groups_vector) assertive.types::assert_is_a_number(group_number) - assertive.files::assert_all_are_dirs(output_path %>% pathological::decompose_path() %>% .$dirname) - assertive.strings::assert_all_are_non_empty_character(output_path %>% pathological::decompose_path() %>% .$filename) + assertive.files::assert_all_are_dirs(output_path %>% fs::path_wd() %>% fs::path_dir()) + assertive.strings::assert_all_are_non_empty_character(output_path %>% fs::path_wd() %>% fs::path_file()) - if (output_path %>% pathological::decompose_path() %>% .$extension %>% stringi::stri_endswith(fixed = "txt")) + if (output_path %>% fs::path_wd() %>% fs::path_ext() %>% stringi::stri_endswith(fixed = "txt")) { output_path_txt <- output_path }else { - output_path_txt <- pathological::decompose_path(output_path) %>% - magrittr::inset2('extension', value = paste(.$extension,'txt', sep = '')) %>% - pathological::recompose_path() + output_path_txt <- output_path %>% fs::path_wd() %>% fs::path_ext_set("txt") } utils::write.table(groups_vector[[group_number]], file = output_path_txt, sep = "\t") - if (output_path %>% pathological::decompose_path() %>% .$extension %>% stringi::stri_endswith(fixed = "csv")) + if (output_path %>% fs::path_wd() %>% fs::path_ext() %>% stringi::stri_endswith(fixed = "csv")) { output_path_csv <- output_path }else { - output_path_csv <- pathological::decompose_path(output_path) %>% - magrittr::inset2('extension', value = paste(.$extension,'csv', sep = '')) %>% - pathological::recompose_path() + output_path_csv <- output_path %>% fs::path_wd() %>% fs::path_ext_set("csv") } utils::write.csv(groups_vector[[group_number]], file = output_path_csv) diff --git a/vignettes/manipulate_term_match_table.Rmd b/vignettes/manipulate_term_match_table.Rmd index 9c109ae..6ece817 100644 --- a/vignettes/manipulate_term_match_table.Rmd +++ b/vignettes/manipulate_term_match_table.Rmd @@ -80,6 +80,8 @@ subset_tmt <- full_tmt[sub_rows,] knitr::kable(subset_tmt) ``` +## Add new rows to the term matching table + New rows can be added. It is mandatory to fill in `term_verbose`, `handle_type` and `handle` in their specific column. `term_verbose` should be a short desription for the column as it will show up as key in the final table. @@ -97,12 +99,16 @@ new_row <- data.frame(term = "example_line", subset_tmt <- rbind(subset_tmt, new_row) ``` -If the row is meant to show an entry of the json `handle_type` needs to be `"list_path"` and `handle` should contain the path to the information in the flattened json after the group number. +If the row is meant to show an entry of the json `handle_type` needs to be `"list_path"` and `handle` should contain the path to the information in the flattened json after the group number. The handle can either be picked by hand and copied and pasted into the column or it can also be searched for. Important is to only take the part after the group number as handle (delete the "Group.1." part). ```{r} # create the flattened json (explained in using_MARMoSET) flat_json <- flatten_json(json = MARMoSET::testfile_json) +``` + +!['handle' is marked blue in this flat json.](fjson_screenshot.JPG) +```{r} # choose/search for item of the flattened list, get path without group number. fj_path <- stringi::stri_subset(names(flat_json), regex = "Flush") %>% stringi::stri_replace_all_regex(pattern = "^Group.[:digit:].", replacement = "") @@ -119,7 +125,7 @@ subset_tmt <- rbind(subset_tmt, new_row) ``` -This so changed term matching table can be used with the function `match_terms()`. +This so changed term matching table can be used with the function `match_terms()`. Of course this table can also be exported and reused. ```{r} subset_table <- one_group_match_terms(flat_json = flat_json, @@ -127,3 +133,4 @@ subset_table <- one_group_match_terms(flat_json = flat_json, group_number = 1) knitr::kable(subset_table[5:7,]) ``` +