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

New imgur_upload with xml2 and httr #1433

Merged
merged 9 commits into from
Sep 20, 2017
Merged

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Sep 17, 2017

Hi @yihui,

Following a PS call in your recent blog post, I modified imgur_upload to use httr and xml2 instead of RCurl and XML

Note that RCurl is also used in knitr::image_uri2 for RCurl::base64Encode. httr has a base64url but not exported. What should we do to remove RCurl suggest dependency to RCurl ?

XML package is used is called inst/examples/knitr-themes.Rnw. I think we can remove the suggests dependency but not sure.

One thing: There is a imguR package with a upload_imgur function. I do not know if it is better to have a imgur_upload function specific to knitr or if it may be a good idea to use a dependency toward imguR package and import the imgur_upload.

What do you think of all this ?
Does it help ?


This change is Reviewable

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Note that RCurl is also used in knitr::image_uri2 for RCurl::base64Encode. httr has a base64url but not exported. What should we do to remove RCurl suggest dependency to RCurl ?

The image_uri2() function can be removed. It is not actually used in this package. I'll take care of it.

XML package is used is called inst/examples/knitr-themes.Rnw. I think we can remove the suggests dependency but not sure.

This Rnw document is not compiled during R CMD build / check, and you can ignore it.

One thing: There is a imguR package with a upload_imgur function. I do not know if it is better to have a imgur_upload function specific to knitr or if it may be a good idea to use a dependency toward imguR package and import the imgur_upload.

For a simple function like imgur_upload(), I'd rather not introduce a new dependency.

BTW, could you sign the contributor agreement? http://www.clahub.com/agreements/yihui/knitr

R/utils-upload.R Outdated
if (!has_package("xml2") || !has_package("httr")) {
stop("Pkg xml2 and httr needed for uploading file to imgur. Please install them or do not upload files.",
call. = FALSE)
}
Copy link
Owner

Choose a reason for hiding this comment

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

I'd remove this if statement, and let httr:: / xml2:: fail directly later.

Copy link
Collaborator Author

@cderv cderv Sep 19, 2017

Choose a reason for hiding this comment

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

I wanted to apply some good practice. Maybe it is not.

R/utils-upload.R Outdated
if (is.null(encoding <- info_media$params$charset)) {
message("No encoding in response : defaulting to UTF-8")
encoding <- "utf-8"
}
Copy link
Owner

Choose a reason for hiding this comment

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

Is it safe to just assume UTF-8? Six lines of code (49-54) to find the encoding is probably not worth it in my eyes. This function does not need to be "bulletproof" :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we can assume that it is UTF-8. I did not found the info on imgurAPI but should be safe. You're right - no need to be too "bulletproof" 😄

@@ -18,8 +18,8 @@ A character string of the link to the image; this string carries an
file; see Imgur API in the references.
}
\description{
This function uses the \pkg{RCurl} package to upload a image to
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for that. I should have read more closely your documentation. I reverted the changes.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Looks good to me now. Thanks!

@cderv
Copy link
Collaborator Author

cderv commented Sep 19, 2017

I took care of your review comments. Thanks.

There is no test for imgur_upload. I tested it with this code.

library(ggplot2)
ggplot(mtcars, aes(mpg, wt)) + geom_point()
ggsave("mtcars.png")
link <- imgur_upload("mtcars.png")
# should open the image on a browser
browseURL(link)
# should give XML attributes
str(attributes(link),1)

Not sure how to implement test with image upload... As it is not there already I did not create a test.

@yihui
Copy link
Owner

yihui commented Sep 19, 2017

Don't worry about the test. This function is called in https://github.com/yihui/knitr-examples/blame/master/010-upload.Rmd and the knitr-examples repo is automatically compiled on Travis. As long as this PR can pass the check on Travis, it should be fine.

BTW, I don't see your name in https://github.com/yihui/knitr/blob/master/DESCRIPTION. Could you add yourself as a contributor there?

@yihui yihui added this to the v0.18 milestone Sep 19, 2017
@cderv
Copy link
Collaborator Author

cderv commented Sep 19, 2017

Yep! I was just thinking about that. I forgot this file. It is not a habit yet as not every project ask you that.
Sorry for the delay as I will do the change in the morning (Paris/France time). But we are not in a hurry.

One more thing, I did not remove XML and RCurl as dependencies in DESCRIPTION. I leave that to you.

@yihui
Copy link
Owner

yihui commented Sep 19, 2017

Sounds good. No hurry.

@cderv
Copy link
Collaborator Author

cderv commented Sep 20, 2017

Done. I had myself as a contributor. It seems to be an alphabetical order of contributor in Authors@R so I respected it.
Thank you for you review and letting me contribute! 😄

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Thanks!

@yihui yihui merged commit 0751802 into yihui:master Sep 20, 2017
yihui added a commit to yihui/yihui.org that referenced this pull request Aug 25, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants