diff --git a/DESCRIPTION b/DESCRIPTION index 0c66ac1..49b040a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,25 +23,23 @@ Description: Reads and writes files to SQLite databases as flobs (a flob is a blob that preserves the file extension). License: MIT + file LICENSE -URL: https://github.com/poissonconsulting/dbflobr +URL: https://github.com/poissonconsulting/dbflobr, https://poissonconsulting.github.io/dbflobr/ BugReports: https://github.com/poissonconsulting/dbflobr/issues Depends: R (>= 3.5) Imports: blob, chk, - clisymbols, - crayon, + cli, DBI, flobr, glue, rlang, RSQLite Suggests: - covr, knitr, rmarkdown, - testthat, + testthat (>= 3.0.0), withr VignetteBuilder: knitr @@ -49,3 +47,5 @@ Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +Config/testthat/edition: 3 +Config/Needs/website: poissonconsulting/poissontemplate diff --git a/R/import.R b/R/import.R index 49a90d6..4c5ab70 100644 --- a/R/import.R +++ b/R/import.R @@ -72,7 +72,7 @@ import_flobs <- function(column_name, table_name, conn, add_blob_column(column_name, table_name, conn) } - ui_line(glue("Writing files to database")) + cli::cli_inform("Writing files to database") success <- rep(FALSE, length = length(files)) names(success) <- names(files) @@ -81,7 +81,9 @@ import_flobs <- function(column_name, table_name, conn, values <- parse_filename(names(files)[i], sep) if (is_length_unequal(values, key)) { - ui_oops(glue("File {i}: can't write {names(files)[i]} to database. The number of hyphen-separated values must be identical to the number of columns in `key`.")) + cli::cli_inform(c( + "x" = "File {i}: can't write {names(files)[i]} to database. The number of hyphen-separated values must be identical to the number of columns in `key`." + )) next } @@ -91,7 +93,9 @@ import_flobs <- function(column_name, table_name, conn, y <- try(read_flob(column_name, table_name, key[i, , drop = FALSE], conn), silent = TRUE) if (!replace && !is_try_error(y)) { - ui_oops(glue("File {i}: can't write {names(files)[i]} to database. Flob already exists in that location and replace = FALSE")) + cli::cli_inform(c( + "x" = "File {i}: can't write {names(files)[i]} to database. Flob already exists in that location and replace = FALSE" + )) next } @@ -107,15 +111,21 @@ import_flobs <- function(column_name, table_name, conn, if (!is_try_error(x)) { success[i] <- TRUE - ui_done(glue("File {i}: {names(files)[i]} written to database")) + cli::cli_inform(c( + "v" = "File {i}: {names(files)[i]} written to database" + )) } else { - ui_oops(glue("File {i}: can't write {names(files)[i]} to database")) + cli::cli_inform(c( + "x" = "File {i}: can't write {names(files)[i]} to database" + )) } next } if (is_try_error(y)) { - ui_done(glue("File {i}: {names(files)[i]} already absent from database.")) + cli::cli_inform(c( + "v" = "File {i}: {names(files)[i]} already absent from database." + )) success[i] <- TRUE next } @@ -127,9 +137,13 @@ import_flobs <- function(column_name, table_name, conn, )) if (!is_try_error(x)) { success[i] <- TRUE - ui_done(glue("File {i}: {names(files)[i]} deleted in database.")) + cli::cli_inform(c( + "v" = "File {i}: {names(files)[i]} deleted in database." + )) } else { - ui_oops(glue("File {i}: can't delete {names(files)[i]} in database.")) + cli::cli_inform(c( + "v" = "File {i}: can't delete {names(files)[i]} in database." + )) } } return(invisible(success)) @@ -178,15 +192,17 @@ import_all_flobs <- function(conn, dir = ".", sep = "_-_", pattern = ".*", table_name <- x[1] column_name <- x[2] inner_dir <- file.path(dir, table_name, column_name) - ui_line(glue("Table name: {ui_value(table_name)}")) - ui_line(glue("Column name: {ui_value(column_name)}")) + cli::cli_inform(c( + "Table name: {.val {table_name}}", + "Column name: {.val {column_name}}" + )) success[[i]] <- import_flobs( column_name = x[2], table_name = x[1], conn = conn, dir = inner_dir, sep = sep, pattern = pattern, sub = sub, exists = exists, replace = replace ) - ui_line("") + cli::cat_line() } names(success) <- sapply(dirs, glue_collapse, "/") diff --git a/R/save.R b/R/save.R index 7f8ea59..013e3c4 100644 --- a/R/save.R +++ b/R/save.R @@ -40,7 +40,7 @@ save_flobs <- function(column_name, table_name, conn, dir = ".", sep = "_-_", su sql <- glue("SELECT {sql_pk(pk)} FROM ('{table_name}');") values <- get_query(sql, conn) - ui_line(glue("Saving files to {ui_value(dir)}")) + cli::cli_inform(("Saving files to {.path {dir}}")) success <- vector() success_names <- vector() @@ -82,12 +82,16 @@ save_flobs <- function(column_name, table_name, conn, dir = ".", sep = "_-_", su dir.create(file.path(dir, new_file), recursive = TRUE) flobr::unflob(x, dir = file.path(dir, new_file), name = new_file, ext = ext, slob = NA, check = FALSE) } - ui_done(glue("Row {i}: file {file} renamed to {new_file_ext}")) + cli::cli_inform(c( + "v" = "Row {i}: file {file} renamed to {new_file_ext}" + )) } else { if (is.na(sub)) { dir.create(file.path(dir, new_file), recursive = TRUE) } - ui_oops(glue("Row {i}: no file found")) + cli::cli_inform(c( + "x" = "Row {i}: no file found" + )) } } names(success) <- success_names @@ -146,13 +150,15 @@ save_all_flobs <- function(table_name = NULL, conn, dir = ".", sep = "_-_", if (!dir.exists(path)) { dir.create(path, recursive = TRUE) } - ui_line(glue("Table name: {ui_value(i)}")) - ui_line(glue("Column name: {ui_value(j)}")) + cli::cli_inform(c( + "Table name: {.val {i}}", + "Column name: {.val {j}}" + )) success[[name]] <- save_flobs(j, i, conn, path, sep = sep, sub = sub, replace = replace ) - ui_line("") + cli::cat_line() } } return(invisible(success)) diff --git a/R/ui.R b/R/ui.R deleted file mode 100644 index 92d31c1..0000000 --- a/R/ui.R +++ /dev/null @@ -1,25 +0,0 @@ -### very simplified versions of usethis functions -bullet <- function(x, bullet) { - bullet <- paste0(bullet, " ", x) - rlang::inform(bullet) -} - -ui_line <- function(x) { - rlang::inform(x) -} - -ui_oops <- function(x) { - bullet(x, crayon::red(clisymbols::symbol$cross)) -} - -ui_done <- function(x) { - bullet(x, crayon::green(clisymbols::symbol$tick)) -} - -ui_value <- function(x) { - if (is.character(x)) { - x <- encodeString(x, quote = "'") - } - x <- crayon::blue(x) - x -} diff --git a/README.Rmd b/README.Rmd index 67e9a57..e6b1c09 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,7 +13,7 @@ knitr::opts_chunk$set( ) ``` -# dbflobr