Skip to content

Commit

Permalink
Merge branch 'DEV' into improving-dplyr-joins
Browse files Browse the repository at this point in the history
  • Loading branch information
zander-prinsloo authored Mar 4, 2024
2 parents 11a436f + d84b2e0 commit 908b7f7
Show file tree
Hide file tree
Showing 26 changed files with 1,466 additions and 1,567 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.9002
Authors@R: c(person(given = "R.Andres",
family = "Castaneda",
email = "[email protected]",
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
24 changes: 6 additions & 18 deletions R/joyn-merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ joyn <- function(x,
x <- copy(x)
y <- copy(y)


## X and Y -----------
check_xy(x,y)

Expand All @@ -233,7 +234,6 @@ joyn <- function(x,
y <- as.data.table(y)
}


## Modify BY when is expression ---------
fixby <- check_by_vars(by, x, y)
by <- fixby$by
Expand Down Expand Up @@ -387,19 +387,6 @@ joyn <- function(x,
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Update x ---------
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# if (isTRUE(update_values) || isTRUE(update_NAs)) {
# var_use <- sub(
# pattern = "\\.y$",
# replacement = "",
# x = newyvars[
# grepl(
# pattern = "\\.y$",
# x = newyvars
# )
# ]
# )
# }
var_use <- NULL
if (isTRUE(update_values) || isTRUE(update_NAs)) {
var_use <- common_vars
Expand Down Expand Up @@ -461,6 +448,11 @@ joyn <- function(x,
.yreport = NULL)


if (sort) {
setorderv(x, by, na.last = na.last)
setattr(x, 'sorted', by)
}

## Rename by variables -----

if (!is.null(fixby$xby)) {
Expand Down Expand Up @@ -518,10 +510,6 @@ joyn <- function(x,
x |> fselect(get(reportvar)) <- NULL
}

if (sort) {
setorderv(x, by, na.last = na.last)
setattr(x, 'sorted', by)
}

if (verbose == TRUE) {
end_joyn <- Sys.time()
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 908b7f7

Please sign in to comment.