Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor use_course() and gain progress reporting #380

Merged
merged 4 commits into from Jun 1, 2018
Merged

Conversation

@jennybc
Copy link
Member

@jennybc jennybc commented Jun 1, 2018

Fixes #276 Refactor use_course()

Thanks @jeroen for all the pointers!

Key things:

  • Explicit use of a handle is how we hook into progress
    reporting, even though curl_download() doesn't expose
  • curl_download() has a built-in check for http status 200
  • Using a custom progressfunction because default doesn't
    always look right in RStudio
  • Switch to fs functions for file system work
Fixes #276

Thanks @jeroen for all the pointers!

Key things:

  * Explicit use of a handle is how we hook into progress
    reporting, even though curl_download() doesn't expose
  * curl_download() has a built-in check for http status 200
  * Using a custom progressfunction because default doesn't
    always look right in RStudio
  * Switch to fs functions for file system work
@jennybc
Copy link
Member Author

@jennybc jennybc commented Jun 1, 2018

Quick screenshot snagged while downloading some hefty course materials from @hadley

screen shot 2018-06-01 at 2 22 31 pm

This updates in place during the download.

R/course.R Outdated
"A ZIP file named:\n",
" ", value(base_name), "\n",
"will be downloaded to this folder:\n",

This comment has been minimized.

@jennybc

jennybc Jun 1, 2018
Author Member

They've already watched the download happen at this point, so seems better to talk about where we're going to put the file.

@@ -328,6 +331,19 @@ parse_content_disposition <- function(cd) {
)
}

progress_fun <- function(down, up) {

This comment has been minimized.

@jennybc

jennybc Jun 1, 2018
Author Member

The default curl progress bar gets mangled in (some versions of?) RStudio, so I took @jeroen's advice to copy an approach from tesseract.

https://github.com/ropensci/tesseract/blob/6514c5862a6e6991c45048449b20fd24babf4bb4/R/tessdata.R#L63-L74

@jennybc jennybc requested a review from hadley Jun 1, 2018
@jennybc
Copy link
Member Author

@jennybc jennybc commented Jun 1, 2018

@jeroen I can't formally request a review from you and I think I followed your advice fairly faithfully, but feel free to comment.

@jeroen
Copy link
Member

@jeroen jeroen commented Jun 1, 2018

Yes I like it, nice how it saves it under the server suggested filename. Maybe somewhere insert a cat("\n") after the download has finished to print the message to a new line?

screen shot 2018-06-01 at 11 37 43 pm

@hadley
hadley approved these changes Jun 1, 2018
R/course.R Outdated
@@ -188,28 +191,27 @@ download_zip <- function(url, destdir = getwd(), pedantic = FALSE) {
message(
"A ZIP file named:\n",
" ", value(base_name), "\n",
"will be downloaded to this folder:\n",
"will be written to this folder:\n",

This comment has been minimized.

@hadley

hadley Jun 1, 2018
Member

copied?

R/course.R Outdated
}
}
full_path <- file.path(base_path, base_name)
full_path <- fs::path(base_path, base_name)

if (!can_overwrite(full_path)) {
## TO DO: it pains me that can_overwrite() always strips to basename
stop("Aborting download", call. = FALSE)

This comment has been minimized.

@hadley

hadley Jun 1, 2018
Member

Reword because it's not the download anymore?

@jennybc jennybc merged commit fdfcfd7 into master Jun 1, 2018
0 of 4 checks passed
0 of 4 checks passed
continuous-integration/appveyor/branch Waiting for AppVeyor build to complete
Details
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
@jennybc jennybc deleted the use-course-progress branch Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants