Skip to content

Commit 35ee852

Browse files
authored
Merge pull request #16 from KWB-R/clean
Clean
2 parents c0eb00a + d8539c3 commit 35ee852

22 files changed

Lines changed: 307 additions & 216 deletions

.github/workflows/R-CMD-check.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,25 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
config:
25-
- {os: macOS-latest, r: 'release'}
26-
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
27-
- {os: windows-latest, r: 'devel'}
25+
- {os: macOS-latest, r: 'release'}
26+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
27+
- {os: windows-latest, r: 'devel'}
2828
- {os: windows-latest, r: 'oldrel'}
2929
- {os: windows-latest, r: 'release'}
3030

3131
env:
32+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3233
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
3334
RSPM: ${{ matrix.config.rspm }}
3435

3536
steps:
3637
- uses: actions/checkout@v2
3738

38-
- uses: r-lib/actions/setup-r@master
39+
- uses: r-lib/actions/setup-r@v2
3940
with:
4041
r-version: ${{ matrix.config.r }}
4142

42-
- uses: r-lib/actions/setup-pandoc@master
43+
- uses: r-lib/actions/setup-pandoc@v2
4344

4445
- name: Query dependencies
4546
run: |

.github/workflows/pkgdown.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v2
1717

18-
- uses: r-lib/actions/setup-r@master
18+
- uses: r-lib/actions/setup-r@v2
1919

20-
- uses: r-lib/actions/setup-pandoc@master
20+
- uses: r-lib/actions/setup-pandoc@v2
2121

2222
- name: Query dependencies
2323
run: |

.github/workflows/pr-commands.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1212
steps:
1313
- uses: actions/checkout@v2
14-
- uses: r-lib/actions/pr-fetch@master
14+
- uses: r-lib/actions/pr-fetch@v2
1515
with:
1616
repo-token: ${{ secrets.GITHUB_TOKEN }}
17-
- uses: r-lib/actions/setup-r@master
17+
- uses: r-lib/actions/setup-r@v2
1818
- name: Install dependencies
1919
run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)'
2020
- name: Document
@@ -23,7 +23,7 @@ jobs:
2323
run: |
2424
git add man/\* NAMESPACE
2525
git commit -m 'Document'
26-
- uses: r-lib/actions/pr-push@master
26+
- uses: r-lib/actions/pr-push@v2
2727
with:
2828
repo-token: ${{ secrets.GITHUB_TOKEN }}
2929
style:
@@ -34,10 +34,10 @@ jobs:
3434
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3535
steps:
3636
- uses: actions/checkout@v2
37-
- uses: r-lib/actions/pr-fetch@master
37+
- uses: r-lib/actions/pr-fetch@v2
3838
with:
3939
repo-token: ${{ secrets.GITHUB_TOKEN }}
40-
- uses: r-lib/actions/setup-r@master
40+
- uses: r-lib/actions/setup-r@v2
4141
- name: Install dependencies
4242
run: Rscript -e 'install.packages("styler")'
4343
- name: Style
@@ -46,6 +46,6 @@ jobs:
4646
run: |
4747
git add \*.R
4848
git commit -m 'Style'
49-
- uses: r-lib/actions/pr-push@master
49+
- uses: r-lib/actions/pr-push@v2
5050
with:
5151
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v2
2020

21-
- uses: r-lib/actions/setup-r@master
21+
- uses: r-lib/actions/setup-r@v2
2222

23-
- uses: r-lib/actions/setup-pandoc@master
23+
- uses: r-lib/actions/setup-pandoc@v2
2424

2525
- name: Query dependencies
2626
run: |

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ Imports:
2929
ggplot2,
3030
kwb.file,
3131
kwb.read,
32-
kwb.utils,
32+
kwb.utils (>= 0.13.0),
3333
magrittr,
3434
openxlsx,
3535
rlang,
3636
stringr,
3737
tibble,
3838
tidyr,
3939
wordcloud2,
40-
xml2,
41-
plotly
40+
xml2
4241
Suggests:
4342
covr,
4443
knitr,
44+
plotly,
4545
rmarkdown
4646
Remotes:
4747
github::kwb-r/kwb.file,
4848
github::kwb-r/kwb.read,
4949
github::kwb-r/kwb.utils
5050
Encoding: UTF-8
5151
LazyData: true
52-
RoxygenNote: 7.1.1
52+
RoxygenNote: 7.2.3
5353
VignetteBuilder: knitr

R/check_for_differences.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#' head(diffs_df)
3939
#'
4040
#' }
41-
check_for_differences <- function(
42-
df_x, df_y, dbg = TRUE) {
41+
check_for_differences <- function(df_x, df_y, dbg = TRUE)
42+
{
4343
name_df_x <- deparse(substitute(df_x))
4444
name_df_y <- deparse(substitute(df_y))
4545

@@ -49,9 +49,9 @@ check_for_differences <- function(
4949
tidy_name <- function(name) paste0(name, "_tidy")
5050

5151
get_text <- function(name_df, name_value) sprintf(
52-
"Tidying data.frame '%s' and rename 'value' to '%s'. Saving to %s",
53-
name_df, name_value, tidy_name(name_df)
54-
)
52+
"Tidying data.frame '%s' and rename 'value' to '%s'. Saving to %s",
53+
name_df, name_value, tidy_name(name_df)
54+
)
5555

5656
df_x_tidy <- kwb.utils::catAndRun(
5757
messageText = get_text(name_df_x, name_value_x), dbg = dbg,
@@ -84,10 +84,12 @@ check_for_differences <- function(
8484

8585
diffs_idx <- kwb.utils::catAndRun(
8686
messageText = messageText, dbg = dbg,
87-
expr = which(!sapply(seq_len(nrow(df_xy_tidy)), function(row) identical(
87+
expr = which(
88+
!sapply(seq_len(nrow(df_xy_tidy)), function(row) identical(
8889
df_xy_tidy[[name_value_x]][row],
8990
df_xy_tidy[[name_value_y]][row]
90-
)))
91+
))
92+
)
9193
)
9294

9395
kwb.utils::catIf(dbg, sprintf(

R/check_problematic_entries.R

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
#' head(problematic_entries)
1414
#' }
1515
check_problematic_entries <- function(
16-
endnote_list, give_hints = TRUE, dbg = TRUE) {
16+
endnote_list,
17+
give_hints = TRUE,
18+
dbg = TRUE
19+
)
20+
{
21+
name <- deparse(substitute(endnote_list))
22+
1723
entries_org <- kwb.utils::catAndRun(
18-
sprintf(
19-
"Creating data frame from '%s'",
20-
deparse(substitute(endnote_list))
21-
),
24+
sprintf("Creating data frame from '%s'", name),
2225
dbg = dbg,
2326
expr = create_references_df(endnote_list)
2427
)
2528

2629
entries_cleaned <- kwb.utils::catAndRun(
27-
sprintf(
28-
"Creating 'cleaned' data frame from '%s' for comparison",
29-
deparse(substitute(endnote_list))
30-
),
30+
sprintf("Creating 'cleaned' data frame from '%s' for comparison", name),
3131
dbg = dbg,
3232
expr = clean_references_df(endnote_list, give_hints, dbg)
3333
)
@@ -36,9 +36,7 @@ check_problematic_entries <- function(
3636
identical(entries_org[[col_name]], entries_cleaned[[col_name]])
3737
})
3838

39-
cols_with_problems <- names(which(has_problems))
40-
41-
check_list <- lapply(cols_with_problems, function(column) {
39+
check_list <- lapply(names(which(has_problems)), function(column) {
4240
indices <- which(!sapply(seq_len(nrow(entries_org)), function(i) {
4341
identical(entries_org[[column]][i], entries_cleaned[[column]][i])
4442
}))

R/clean_references_df.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#' @export
77
#' @importFrom stringr str_remove_all regex str_trim
88
#' @importFrom kwb.utils catAndRun
9-
clean_dois <- function(dois, dbg = TRUE) {
9+
clean_dois <- function(dois, dbg = TRUE)
10+
{
1011
remove <- stringr::str_remove_all
1112

1213
kwb.utils::catAndRun("Clean 'DOI'", dbg = dbg, expr = {
@@ -28,8 +29,8 @@ clean_dois <- function(dois, dbg = TRUE) {
2829
#' @export
2930
#' @importFrom stringr str_remove_all str_replace_all regex str_trim
3031
#' @importFrom kwb.utils catAndRun
31-
clean_project_names <- function(
32-
project_names, give_hints = FALSE, dbg = TRUE) {
32+
clean_project_names <- function(project_names, give_hints = FALSE, dbg = TRUE)
33+
{
3334
kwb.utils::catAndRun("Clean 'Project Names'", dbg = dbg, expr = {
3435
project_names <- project_names %>%
3536
stringr::str_replace_all("\\s+?/", ",") %>%
@@ -68,8 +69,8 @@ if (FALSE) {
6869
#' @return vector with cleaned author names
6970
#' @export
7071
#' @importFrom kwb.utils catAndRun
71-
clean_author_names <- function(
72-
author_names, give_hints = FALSE, dbg = TRUE) {
72+
clean_author_names <- function(author_names, give_hints = FALSE, dbg = TRUE)
73+
{
7374
kwb.utils::catAndRun(
7475
"No cleaning of author_names implemented yet. Only hints are generated in
7576
case that user defines 'give_hints = TRUE' (default: FALSE)",
@@ -94,8 +95,8 @@ clean_author_names <- function(
9495
#' @return vector with cleaned accessibility information
9596
#' @export
9697
#' @importFrom stringr str_remove_all str_replace_all regex str_trim
97-
clean_accessibility <- function(
98-
access, give_hints = FALSE, dbg = TRUE) {
98+
clean_accessibility <- function(access, give_hints = FALSE, dbg = TRUE)
99+
{
99100
replace_all <- function(string, pattern, replacement) {
100101
stringr::str_replace_all(
101102
string = string,
@@ -133,7 +134,8 @@ clean_accessibility <- function(
133134
#' refs_clean_df <- clean_references_df(endnote_list)
134135
#' head(refs_clean_df)
135136
#' }
136-
clean_references_df <- function(endnote_list, give_hints = FALSE, dbg = TRUE) {
137+
clean_references_df <- function(endnote_list, give_hints = FALSE, dbg = TRUE)
138+
{
137139
refs_df <- create_references_df(endnote_list, collapse = TRUE)
138140

139141
refs_df <- kwb.utils::catAndRun(

R/create_df_from_endnote_xml.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,29 @@
1414
#' references_df <- create_df_from_endnote_xml()
1515
#' head(references_df)
1616
#'
17-
create_df_from_endnote_xml <- function(endnote_xml = default_xml()) {
17+
create_df_from_endnote_xml <- function(endnote_xml = default_xml())
18+
{
1819
references <- kwb.read::read_xml_as_path_value(endnote_xml)
1920

2021
xml_paths <- references$path %>%
2122
stringr::str_remove_all(pattern = "^/xml/records/record")
2223

2324
references_df <- kwb.utils::asNoFactorDataFrame(cbind(
2425
kwb.file::to_subdir_matrix(xml_paths),
25-
references[, -1]
26+
references[, -1L]
2627
))
2728

28-
references_df[, 1] <- as.numeric(stringr::str_remove_all(
29-
references_df[, 1], "\\[|\\]"
29+
references_df[, 1L] <- as.numeric(stringr::str_remove_all(
30+
references_df[, 1L], "\\[|\\]"
3031
))
3132

3233
n_col <- ncol(references_df)
3334

34-
colnames(references_df) <- c("record_id", paste0("key", 1:(n_col - 2)), "value")
35+
colnames(references_df) <- c(
36+
"record_id",
37+
paste0("key", seq_len(n_col - 2L)),
38+
"value"
39+
)
3540

3641
endnote_df <- dplyr::left_join(
3742
references_df,
@@ -41,7 +46,8 @@ create_df_from_endnote_xml <- function(endnote_xml = default_xml()) {
4146
add_file_info_attributes(endnote_df, endnote_xml)
4247
}
4348

44-
if (FALSE) {
49+
if (FALSE)
50+
{
4551
abstracts <- references_df %>%
4652
dplyr::filter(.data$key1 == "abstract") %>%
4753
dplyr::group_by(

R/create_endnote_list.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#' str(endnote_list[1]$record)
1111
#' attr(endnote_list, "xml_file_info")
1212
#' attr(endnote_list, "xml_filename_without_extension")
13-
create_endnote_list <- function(endnote_xml = default_xml()) {
13+
create_endnote_list <- function(endnote_xml = default_xml())
14+
{
1415
endnote_list <- xml2::as_list(xml2::read_xml(endnote_xml))$xml$records
1516

16-
1717
add_file_info_attributes(endnote_list, endnote_xml)
1818
}

0 commit comments

Comments
 (0)