Skip to content

Commit

Permalink
Merge pull request #46 from randrescastaneda/collapse_message
Browse files Browse the repository at this point in the history
Collapse message CU-8687a4mwt
  • Loading branch information
zander-prinsloo authored Feb 23, 2024
2 parents a2226ea + 7a04cb1 commit 144231a
Show file tree
Hide file tree
Showing 24 changed files with 1,458 additions and 1,547 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, website]
branches: [main, DEV]
pull_request:
branches: [main, master, website]
branches: [main, DEV]

name: R-CMD-check

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, website]
branches: [main, DEV]
pull_request:
branches: [main, master, website]
branches: [main, DEV]

name: test-coverage

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: joyn
Type: Package
Title: Tool for Diagnosis of Tables Joins and Complementary Join Features
Version: 0.1.6
Version: 0.1.6.9001
Authors@R: c(person(given = "R.Andres",
family = "Castaneda",
email = "acastanedaa@worldbank.org",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# joyn (development version)

# joyn 0.1.6

# joyn 0.1.5
Expand Down
12 changes: 9 additions & 3 deletions R/info_display.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' display type of joyn message
#'
#' @param type character: one or more of the following:
#' `r cli::format_inline("{.or {.val {type_choices()}}}")` or `all`
#' @param type character: one or more of the following: `r joyn:::type_choices()`
#' cli::format_inline("{.or {.val {type_choices()}}}")` or `all`
#' @param msg character vector to be parsed to [cli::cli_abort()]. Default is
#' NULL. It only works if `"err" %in% type`
#'
#' @return returns data frame with message invisibly. print message in console
#' @export
Expand All @@ -19,7 +21,8 @@
#'
#' joyn_msg("all")

joyn_msg <- function(type = c("all", type_choices())) {
joyn_msg <- function(type = c("all", type_choices()),
msg = NULL) {

# Check ---------
type_to_use <- match.arg(type, several.ok = TRUE)
Expand All @@ -39,6 +42,9 @@ joyn_msg <- function(type = c("all", type_choices())) {
cli::cli_text(.)
})

if ("err" %in% type_to_use & is.character(msg)) {
cli::cli_abort(msg)
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Return ---------
Expand Down
111 changes: 85 additions & 26 deletions R/joyn_workhorse.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,92 @@ joyn_workhorse <- function(
# Do a full join -------------------------------------------------------------

# if not 1:1 => use merge.data.table
if (match_type == "m:m") {

dt_result <- data.table::merge.data.table(
x = x,
y = y,
by = by,
all = TRUE,
sort = FALSE,
suffixes = suffixes,
allow.cartesian = TRUE
)

} else {

# not m:m => use collapse::join()
dt_result <- collapse::join( x = x,
y = y,
how = "full",
on = by,
multiple = TRUE, # matches row in x with m in y
validate = "m:m", # no checks performed
suffix = suffixes, # data.table suffixes
keep.col.order = TRUE,
verbose = 0,
column = NULL
)
}
# not m:m => use collapse::join()
dt_result <- tryCatch(
expr = {
source_pkg <- if (match_type == "m:m") "data.table::merge" else "collapse::join"
if (match_type == "m:m") {
data.table::merge.data.table(
x = x,
y = y,
by = by,
all = TRUE,
sort = FALSE,
suffixes = suffixes,
allow.cartesian = TRUE
)

} else {
collapse::join( x = x,
y = y,
how = "full",
on = by,
multiple = TRUE, # matches row in x with m in y
validate = "m:m", # no checks performed
suffix = suffixes, # data.table suffixes
keep.col.order = TRUE,
verbose = 0,
column = NULL)
}
}, # end of expr section

error = function(e) {


joyn_msg("err", c("{.pkg {source_pkg}} returned the following:",
x = e$message))
}, # end of error section

warning = function(w) {
if (grepl("[Oo]veridentified", w$message)) {
store_msg(
type = "warn",
ok = paste(cli::symbol$warning, "\nWarning: "),
pale = "Your data is overidentified. Below the original message from {.pkg {source_pkg}}:",
bolded_pale = "\n{w$message}"
)
} else {
store_msg(
type = "warn",
ok = paste(cli::symbol$warning, "\nWarning: "),
pale = "{.pkg {source_pkg}} returned the following warning:",
bolded_pale = "\n{w$message}"
)
}

# This is inefficient but it is the only way to return the table when
# there is a warning

if (match_type == "m:m") {
data.table::merge.data.table(
x = x,
y = y,
by = by,
all = TRUE,
sort = FALSE,
suffixes = suffixes,
allow.cartesian = TRUE
) |>
suppressWarnings()

} else {
collapse::join( x = x,
y = y,
how = "full",
on = by,
multiple = TRUE, # matches row in x with m in y
validate = "m:m", # no checks performed
suffix = suffixes, # data.table suffixes
keep.col.order = TRUE,
verbose = 0,
column = NULL) |>
suppressWarnings()
}

}

) # End of trycatch

# Calculate the time taken
end_time <- Sys.time()
Expand Down
7 changes: 6 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ navbar:
- reference
- articles
- news
right: github
right:
- Dev version
- github
components:
reference:
text: Reference
href: reference/index.html
dev version:
text: dev version
href: dev/
github:
icon: fab fa-github fa-lg
href: https://github.com/randrescastaneda/joyn/
Expand Down
13 changes: 10 additions & 3 deletions docs/dev/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions docs/dev/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 144231a

Please sign in to comment.