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

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 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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 June 1, 2018 21:27
@jennybc
Copy link
Member Author

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 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

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reword because it's not the download anymore?

@jennybc jennybc merged commit fdfcfd7 into master Jun 1, 2018
@jennybc jennybc deleted the use-course-progress branch June 1, 2018 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants