Skip to content

Commit

Permalink
fs instead of pathological
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiweler committed Jul 5, 2019
1 parent daffa46 commit 8c37aab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Imports:
assertive.strings,
assertive.types,
dplyr,
fs,
jsonlite,
magrittr,
pathological,
rlist,
stringi,
tidyr,
Expand Down
16 changes: 6 additions & 10 deletions R/output_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions vignettes/manipulate_term_match_table.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 = "")
Expand All @@ -119,11 +125,12 @@ 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,
term_matching_table = subset_tmt,
group_number = 1)
knitr::kable(subset_table[5:7,])
```

0 comments on commit 8c37aab

Please sign in to comment.