Skip to content

Commit

Permalink
backwards compatibility
Browse files Browse the repository at this point in the history
Remove dep on utils::askYesNo. Closes #17
  • Loading branch information
cboettig committed Sep 7, 2018
1 parent 00e7569 commit 6167e27
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: arkdb
Version: 0.0.2
Version: 0.0.3
Title: Archive and Unarchive Databases Using Flat Files
Description: Flat text files provide a robust, compressible, and portable
way to store tables from databases. This package provides convenient
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ importFrom(DBI,dbSendQuery)
importFrom(DBI,dbWriteTable)
importFrom(progress,progress_bar)
importFrom(tools,file_ext)
importFrom(utils,askYesNo)
importFrom(utils,read.table)
importFrom(utils,write.table)
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# arkdb 0.0.2
# arkdb 0.0.3

* Remove dependency on utils::askYesNo for backward compatibility, [#17](https://github.com/ropensci/arkdb/issues/17)

# arkdb 0.0.2 2018-08-20 (First release to CRAN)

* Ensure the suggested dependency MonetDBLite is available before running unit test using it.

Expand Down
31 changes: 27 additions & 4 deletions R/assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,44 @@ dont_overwrite <- function(filename){
FALSE
}

#' @importFrom utils askYesNo
ask_overwrite <- function(filename){
if(!interactive()){
return(overwrite(filename))
}

replace <- askYesNo(paste0("Overwrite ", basename(filename), "?"))
replace <- askyesno(paste0("Overwrite ", basename(filename), "?"))
if(is.na(replace)){
stop(paste("operation cancelled."), call. = FALSE)
}
if(!replace){
return(dont_overwrite(filename))
}

overwrite(filename)
}


# utils::askYesKnow is new to R 3.5.0; avoid for backwards compatibility
askyesno <- function(msg){

prompts <- c("Yes", "No", "Cancel")
choices <- tolower(prompts)
msg1 <- paste0("(", paste(choices, collapse = "/"), ") ")

if (nchar(paste0(msg, msg1)) > 250) {
cat(msg, "\n")
msg <- msg1
}
else msg <- paste0(msg, " ", msg1)

ans <- readline(msg)
match <- pmatch(tolower(ans), tolower(choices))

if (!nchar(ans))
TRUE
else if (is.na(match))
stop("Unrecognized response ", dQuote(ans))
else c(TRUE, FALSE, NA)[match]
}


assert_overwrite_db <- function(db_con, tablename, overwrite){
Expand All @@ -95,7 +118,7 @@ ask_overwrite_db <- function(con, tablename){
return(overwrite_db(con, tablename))
}

if(!askYesNo(paste0("Overwrite ", tablename, "?"))){
if(!askyesno(paste0("Overwrite ", tablename, "?"))){
return(dont_overwrite(tablename))
}

Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Consider the `nycflights` database in SQLite:
``` r
tmp <- tempdir() # Or can be your working directory, "."
db <- dbplyr::nycflights13_sqlite(tmp)
#> Caching nycflights db at /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T//RtmpvsQbO6/nycflights13.sqlite
#> Caching nycflights db at /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T//RtmpJ5461F/nycflights13.sqlite
#> Creating table: airlines
#> Creating table: airports
#> Creating table: flights
Expand All @@ -72,15 +72,15 @@ Create an archive of the database:
dir <- fs::dir_create(fs::path(tmp, "nycflights"))
ark(db, dir, lines = 50000)
#> Exporting airlines in 50000 line chunks:
#> ...Done! (in 0.008452892 secs)
#> ...Done! (in 0.006890059 secs)
#> Exporting airports in 50000 line chunks:
#> ...Done! (in 0.02827597 secs)
#> ...Done! (in 0.03808403 secs)
#> Exporting flights in 50000 line chunks:
#> ...Done! (in 15.24916 secs)
#> ...Done! (in 12.81669 secs)
#> Exporting planes in 50000 line chunks:
#> ...Done! (in 0.05896616 secs)
#> ...Done! (in 0.04250216 secs)
#> Exporting weather in 50000 line chunks:
#> ...Done! (in 1.423234 secs)
#> ...Done! (in 1.38778 secs)
```

## Unarchive
Expand All @@ -93,19 +93,19 @@ files <- fs::dir_ls(dir)
new_db <- src_sqlite(fs::path(tmp, "local.sqlite"), create=TRUE)

unark(files, new_db, lines = 50000)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/nycflights/airlines.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.0220139 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/nycflights/airports.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.06350207 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/nycflights/flights.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 18.38258 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/nycflights/planes.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.1244881 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/nycflights/weather.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.698673 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/nycflights/airlines.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.01596403 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/nycflights/airports.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.06146502 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/nycflights/flights.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 8.835862 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/nycflights/planes.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.04995394 secs)
#> Importing /var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/nycflights/weather.tsv.bz2 in 50000 line chunks:
#> ...Done! (in 0.5743668 secs)

new_db
#> src: sqlite 3.22.0 [/var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpvsQbO6/local.sqlite]
#> src: sqlite 3.22.0 [/var/folders/y8/0wn724zs10jd79_srhxvy49r0000gn/T/RtmpJ5461F/local.sqlite]
#> tbls: airlines, airports, flights, planes, weather
```

Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"codeRepository": "https://github.com/ropensci/arkdb",
"issueTracker": "https://github.com/ropensci/arkdb/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.0.2",
"version": "0.0.3",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -237,7 +237,7 @@
],
"releaseNotes": "https://github.com/ropensci/arkdb/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/arkdb/blob/master/README.md",
"fileSize": "16.632KB",
"fileSize": "16.968KB",
"contIntegration": [
"https://travis-ci.org/cboettig/arkdb",
"https://codecov.io/github/cboettig/arkdb?branch=master",
Expand Down
8 changes: 4 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Dear CRAN maintainers,

This release patches the issue in which a unit-test attempted to use a Suggested
package without first checking that said package was installed. This also corrects
a grammatical error in the package DESCRIPTION.
This release avoids the use of utils::askYesNo in order to maintain
greater backwards compatibility with R versions prior to 3.5.0


## Test environments

* local OS X install, R 3.5.1
* ubuntu 14.04 (on travis-ci), R 3.5.1
* win-builder (devel and release)

## R CMD check results

0 errors | 0 warnings | 1 note
0 errors | 0 warnings | 0 notes

* This is a new release.

0 comments on commit 6167e27

Please sign in to comment.