Skip to content

Commit

Permalink
Merge tag 'v0.1.9' into docs
Browse files Browse the repository at this point in the history
dm 0.1.9

- New `vignette("howto-dm-copy", package = "dm")` and `vignette("howto-dm-rows", package = "dm")` discuss updating data on the database. In part derived from `vignette("howto-dm-db", package = "dm")` (#411, @jawond).
- New `dm_mutate_tbl()` (#448).
- `dm_financial()` falls back to db-edu.pacha.dev if relational.fit.cvut.cz is unavailable (#446, @pachamaltese).
- Use testthat 3e (#455).
  • Loading branch information
krlmlr committed Nov 19, 2020
2 parents b65116d + 1b0d9eb commit bab3c2a
Show file tree
Hide file tree
Showing 62 changed files with 2,061 additions and 525 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/tic.yml
Expand Up @@ -35,19 +35,21 @@ jobs:
# [Custom matrix env var]
- { os: windows-latest, r: "release", id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: "release", TIC_ONLY_STYLER: true, id: "TIC_ONLY_STYLER" }
- { os: ubuntu-16.04, r: "release", TIC_ONLY_STYLER: true, id: "TIC_ONLY_STYLER" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: 3.6, id: "default" }
- { os: ubuntu-16.04, r: 4.0, id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: 3.5, id: "default" }
- { os: ubuntu-16.04, r: 3.6, id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: 3.4, id: "default" }
- { os: ubuntu-16.04, r: 3.5, id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: 3.3, id: "default" }
- { os: ubuntu-16.04, r: 3.4, id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: "release", TIC_ONLY_IMPORTS: true, id: "TIC_ONLY_IMPORTS" }
- { os: ubuntu-16.04, r: 3.3, id: "default" }
# [Custom matrix env var]
- { os: ubuntu-latest, r: "release", TIC_CHECK_FINANCIAL: true, id: "TIC_CHECK_FINANCIAL" }
- { os: ubuntu-16.04, r: "release", TIC_ONLY_IMPORTS: true, id: "TIC_ONLY_IMPORTS" }
# [Custom matrix env var]
- { os: ubuntu-16.04, r: "release", TIC_CHECK_FINANCIAL: true, id: "TIC_CHECK_FINANCIAL" }

env:
# [Custom env var]
Expand Down Expand Up @@ -114,8 +116,8 @@ jobs:
uses: pat-s/always-upload-cache@v2.0.0
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ steps.date.outputs.date }}-${{ matrix.config.cache }}-${{ matrix.config.id }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ steps.date.outputs.date }}-${{ matrix.config.cache }}-${{ matrix.config.id }}
key: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-2-${{ steps.date.outputs.date }}-${{ matrix.config.cache }}-${{ matrix.config.id }}
restore-keys: ${{ matrix.config.os }}-r-${{ matrix.config.r }}-2-${{ steps.date.outputs.date }}-${{ matrix.config.cache }}-${{ matrix.config.id }}

# install ccache and write config file
- name: "[Linux] Prepare"
Expand Down
8 changes: 5 additions & 3 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: dm
Title: Relational Data Models
Version: 0.1.7
Date: 2020-09-01
Version: 0.1.9
Date: 2020-11-18
Authors@R:
c(person(given = "Tobias",
family = "Schieferdecker",
Expand Down Expand Up @@ -66,6 +66,7 @@ Suggests:
fansi,
keyring,
knitr,
mockr,
nycflights13,
odbc,
RMariaDB (>= 1.0.10),
Expand All @@ -81,4 +82,5 @@ Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE, roclets = c("collate",
"namespace", "rd"))
RoxygenNote: 7.1.1.9000
RoxygenNote: 7.1.1.9001
Config/testthat/edition: 3
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -11,7 +11,7 @@ qtest: qtest-sqlite qtest-postgres qtest-mssql
test: test-sqlite test-postgres test-mssql

qtest-%:
DM_TEST_SRC=$@ time R -q -e 'options("testthat.summary.omit_skips" = TRUE, "crayon.enabled" = TRUE); devtools::test(filter = "${DM_TEST_FILTER}", reporter = c("summary", "fail"))'
TESTTHAT_PARALLEL=FALSE DM_TEST_SRC=$@ time R -q -e 'options("crayon.enabled" = TRUE); testthat::test_local(filter = "${DM_TEST_FILTER}")'

test-%:
DM_TEST_SRC=$@ time R -q -e 'devtools::test(filter = "${DM_TEST_FILTER}", reporter = c("progress", "summary", "fail"))'
DM_TEST_SRC=$@ time R -q -e 'testthat::test_local(filter = "${DM_TEST_FILTER}")'
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -202,6 +202,7 @@ export(dm_has_pk)
export(dm_insert_zoomed)
export(dm_is_referenced)
export(dm_join_to_tbl)
export(dm_mutate_tbl)
export(dm_nrow)
export(dm_nycflights13)
export(dm_paste)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
@@ -1,3 +1,11 @@
# dm 0.1.9

- New `vignette("howto-dm-copy", package = "dm")` and `vignette("howto-dm-rows", package = "dm")` discuss updating data on the database. In part derived from `vignette("howto-dm-db", package = "dm")` (#411, @jawond).
- New `dm_mutate_tbl()` (#448).
- `dm_financial()` falls back to db-edu.pacha.dev if relational.fit.cvut.cz is unavailable (#446, @pachamaltese).
- Use testthat 3e (#455).


# dm 0.1.7

- Bump RMariaDB required version to 1.0.10 to work around timeout with `R CMD check`.
Expand Down
48 changes: 45 additions & 3 deletions R/add-tbl.R
@@ -1,12 +1,12 @@
#' Add tables to a [`dm`]
#'
#' @description
#' `dm_add_tbl()` adds one or more tables to a [`dm`].
#' It uses [mutate()] semantics.
#' Adds one or more new tables to a [`dm`].
#' Existing tables are not overwritten.
#'
#' @return The initial `dm` with the additional table(s).
#'
#' @seealso [dm_rm_tbl()]
#' @seealso [dm_mutate_tbl()], [dm_rm_tbl()]
#'
#' @param dm A [`dm`] object.
#' @param ... One or more tables to add to the `dm`.
Expand Down Expand Up @@ -101,3 +101,45 @@ check_new_tbls <- function(dm, tbls) {
abort_not_same_src()
}
}

#' Update tables in a [`dm`]
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' Updates one or more existing tables in a [`dm`].
#' For now, the column names must be identical.
#' This restriction may be levied optionally in the future.
#'
#' @seealso [dm_add_tbl()], [dm_rm_tbl()]
#'
#' @param dm A [`dm`] object.
#' @param ... One or more tables to update in the `dm`.
#' Must be named.
#'
#' @examplesIf rlang::is_installed("nycflights13")
#' dm_nycflights13() %>%
#' dm_mutate_tbl(flights = nycflights13::flights[1:3, ])
#'
#' @export
dm_mutate_tbl <- function(dm, ...) {
check_not_zoomed(dm)

old_names <- src_tbls(dm)

new_tables <- list2(...)
stopifnot(is_named(new_tables))

new_names <- names(new_tables)
stopifnot(new_names %in% old_names)

old_tables <- dm_get_tables_impl(dm)

stopifnot(identical(map(new_tables, colnames), map(old_tables[new_names], colnames)))

old_tables[new_names] <- new_tables

def <- dm_get_def(dm)
def$data <- old_tables
new_dm3(def)
}
2 changes: 1 addition & 1 deletion R/db-interface.R
Expand Up @@ -36,7 +36,7 @@
#' as the original table names.
#'
#' Use a variant of
#' `table_names = ~ DBI::SQL(dbplyr::in_schema("schema_name", .x))`
#' `table_names = ~ DBI::SQL(paste0("schema_name", ".", .x))`
#' to specify the same schema for all tables.
#' Use `table_names = identity` with `temporary = TRUE`
#' to avoid giving temporary tables unique names.
Expand Down
14 changes: 9 additions & 5 deletions R/dm.R
Expand Up @@ -502,12 +502,8 @@ format.dm <- function(x, ...) { # for both dm and zoomed_dm

#' @export
format.zoomed_dm <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) {
df <- get_zoomed_tbl(x)
# so far only 1 table can be zoomed on
zoomed_df <- new_zoomed_df(
df,
name_df = orig_name_zoomed(x)
)
zoomed_df <- as_zoomed_df(x)
cat_line(format(zoomed_df, ..., n = n, width = width, n_extra = n_extra))
invisible(x)
}
Expand All @@ -528,6 +524,14 @@ def_get_n_fks <- function(def) {
sum(map_int(def$fks, vctrs::vec_size))
}

as_zoomed_df <- function(x) {
# for tests
new_zoomed_df(
get_zoomed_tbl(x),
name_df = orig_name_zoomed(x)
)
}

new_zoomed_df <- function(x, ...) {
if (!is.data.frame(x)) {
return(structure(x, class = c("zoomed_df", class(x)), ...))
Expand Down
2 changes: 1 addition & 1 deletion R/error-helpers.R
Expand Up @@ -62,7 +62,7 @@ abort_not_subset_of <- function(table_name_1, colname_1,
error_txt_not_subset_of <- function(table_name_1, colname_1,
table_name_2, colname_2) {
glue(
"Column {tick(colname_1)} of table {tick(table_name_1)} contains values (see above) that are not present in column ",
"Column {tick(colname_1)} of table {tick(table_name_1)} contains values (see examples above) that are not present in column ",
"{tick(colname_2)} of table {tick(table_name_2)}."
)
}
Expand Down
34 changes: 34 additions & 0 deletions R/financial-db-con.R
@@ -0,0 +1,34 @@
#' Connection to SQL Financial Database
#' @description Connects to relational.fit.cvut.cz unless the service is
#' unavailable, in which case db-edu.pacha.dev is used as a fallback
#' @return A `MariaDBConnection` object
financial_db_con <- function() {
err_relational <- tryCatch(return(relational_con()), error = identity)
err_dbedu <- tryCatch(return(dbedu_con()), error = identity)

abort(paste0(
"Can't connect to relational.fit.cvut.cz or db-edu.pacha.dev:\n",
conditionMessage(err_relational), "\n",
conditionMessage(err_dbedu)
))
}

relational_con <- function() {
DBI::dbConnect(
RMariaDB::MariaDB(),
username = "guest",
password = "relational",
dbname = "Financial_ijs",
host = "relational.fit.cvut.cz"
)
}

dbedu_con <- function() {
DBI::dbConnect(
RMariaDB::MariaDB(),
username = "student",
password = "tx5mvyRQqD",
dbname = "loan_application",
host = "db-edu.pacha.dev"
)
}
9 changes: 2 additions & 7 deletions R/financial.R
Expand Up @@ -10,20 +10,15 @@
#'
#' @return A `dm` object.
#'
#' @inheritParams financial_db_con
#' @export
#' @examplesIf dm:::dm_has_financial() && rlang::is_installed("DiagrammeR")
#' dm_financial() %>%
#' dm_draw()
dm_financial <- function() {
stopifnot(rlang::is_installed("RMariaDB"))

my_db <- DBI::dbConnect(
RMariaDB::MariaDB(),
username = "guest",
password = "relational",
dbname = "Financial_ijs",
host = "relational.fit.cvut.cz"
)
my_db <- financial_db_con()

my_dm <-
dm_from_src(my_db, learn_keys = FALSE) %>%
Expand Down
2 changes: 1 addition & 1 deletion R/flatten.R
Expand Up @@ -264,7 +264,7 @@ prepare_dm_for_flatten <- function(dm, tables, gotta_rename) {
# renaming will be minimized if we reduce the `dm` to the necessary tables here
red_dm <-
dm_reset_all_filters(dm) %>%
dm_select_tbl(tables)
dm_select_tbl(!!!tables)
# Only need to compute `tbl(dm, start)`, `dm_apply_filters()` not necessary
# Need to use `dm` and not `clean_dm` here, because of possible filter conditions.
start_tbl <- dm_get_filtered_table(dm, start)
Expand Down
2 changes: 1 addition & 1 deletion R/foreign-keys.R
Expand Up @@ -380,8 +380,8 @@ check_fk <- function(t1, t1_name, colname, t2, t2_name, pk) {
ungroup() %>% # dbplyr problem?
mutate(n_mismatch = sum(if_else(is.na(mismatch_or_null), 0L, n), na.rm = TRUE)) %>%
mutate(n_total = sum(n, na.rm = TRUE)) %>%
arrange(desc(n)) %>%
filter(!is.na(mismatch_or_null)) %>%
arrange(desc(n)) %>%
head(MAX_COMMAS + 1L) %>%
collect(),
error = identity
Expand Down
3 changes: 2 additions & 1 deletion R/key-helpers.R
Expand Up @@ -174,7 +174,8 @@ check_subset <- function(t1, c1, t2, c2) {
v2 <- pull(eval_tidy(t2q), !!ensym(c2q))

setdiff_v1_v2 <- setdiff(v1, v2)
print(filter(eval_tidy(t1q), !!c1q %in% setdiff_v1_v2))
# collect() for robust test output
print(collect(filter(eval_tidy(t1q), !!c1q %in% setdiff_v1_v2)), n = 10)

abort_not_subset_of(as_label(t1q), as_name(c1q), as_label(t2q), as_name(c2q))
}
Expand Down
2 changes: 1 addition & 1 deletion R/learn.R
Expand Up @@ -298,6 +298,6 @@ nest_compat <- function(.data, ...) {
mutate(!!new_col := !!nest)
} else {
nest(.data, ...) %>%
mutate_at(vars(new_col), vctrs::as_list_of)
mutate_at(vars(!!!new_col), vctrs::as_list_of)
}
}
3 changes: 1 addition & 2 deletions R/table-surgery.R
Expand Up @@ -57,9 +57,8 @@ decompose_table <- function(.data, new_id_column, ...) {
parent_table <-
select(.data, !!!sel_vars$indices) %>%
distinct() %>%
arrange(!!!syms(names(sel_vars$indices))) %>%
# Without as.integer(), RPostgres creates integer64 column (#15)
mutate(!!id_col_q := as.integer(row_number())) %>%
mutate(!!id_col_q := as.integer(row_number(!!sym(names(sel_vars$indices)[[1]])))) %>%
select(!!id_col_q, everything())

non_key_indices <-
Expand Down
2 changes: 1 addition & 1 deletion R/zoom.R
Expand Up @@ -14,7 +14,7 @@
#'
#' `dm_discard_zoomed()` discards the zoomed table and returns the `dm` as it was before zooming.
#'
#' Please refer to `vignette("dm-zoom-to-table", package = "dm")`
#' Please refer to `vignette("tech-db-zoom", package = "dm")`
#' for a more detailed introduction.
#'
#' @inheritParams dm_add_pk
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Expand Up @@ -26,7 +26,7 @@ knit_print.grViz <- function(x, ..., options) {
vctrs::s3_register("knitr::knit_print", "grViz")
```

# [dm](https://krlmlr.github.io/dm)
# [dm](https://krlmlr.github.io/dm/)

<!-- badges: start -->
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
Expand Down Expand Up @@ -141,7 +141,7 @@ License: MIT © cynkra GmbH.

Funded by:

[![energie360°](man/figures/energie-72.png)](https://www.energie360.ch)
[![energie360°](man/figures/energie-72.png)](https://www.energie360.ch/de/)
<span style="padding-right:50px">
</span>
[![cynkra](man/figures/cynkra-72.png)](https://www.cynkra.com/)
Expand Down
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->

# [dm](https://krlmlr.github.io/dm)
# [dm](https://krlmlr.github.io/dm/)

<!-- badges: start -->

Expand Down Expand Up @@ -139,7 +139,7 @@ License: MIT © cynkra GmbH.

Funded by:

[![energie360°](man/figures/energie-72.png)](https://www.energie360.ch) <span style="padding-right:50px"> </span> [![cynkra](man/figures/cynkra-72.png)](https://www.cynkra.com/)
[![energie360°](man/figures/energie-72.png)](https://www.energie360.ch/de/) <span style="padding-right:50px"> </span> [![cynkra](man/figures/cynkra-72.png)](https://www.cynkra.com/)

-----

Expand Down
15 changes: 8 additions & 7 deletions cran-comments.md
@@ -1,17 +1,18 @@
dm 0.1.7
dm 0.1.9

## Cran Repository Policy

- [x] Reviewed CRP last edited 2020-07-11.
- [x] Reviewed CRP last edited 2020-10-29.

## R CMD check results

- [x] Checked locally, R 4.0.2
- [x] Checked on CI system, R 4.0.2
- [x] Checked locally, R 4.0.3
- [x] Checked on CI system, R 4.0.3
- [x] Checked on win-builder, R devel

Check the boxes above after successful execution and remove this line. Then run `fledge::release()`.

## Current CRAN check results

- [x] Checked on 2020-09-01, problems found: https://cran.r-project.org/web/checks/check_results_dm.html
- [x] NOTE: r-patched-solaris-x86: RPostgres not available
- [x] ERROR: (on various platforms): Now connecting with a timeout to Internet data source
- [x] Checked on 2020-11-18, problems found: https://cran.r-project.org/web/checks/check_results_dm.html
- [x] NOTE: r-patched-solaris-x86: RPostgres is not available on Solaris.
2 changes: 1 addition & 1 deletion man/copy_dm_to.Rd

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

0 comments on commit bab3c2a

Please sign in to comment.