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

added cir_img() function #272

Merged
merged 7 commits into from
Aug 20, 2020
Merged

added cir_img() function #272

merged 7 commits into from
Aug 20, 2020

Conversation

andschar
Copy link
Contributor

@andschar andschar commented Jul 14, 2020

Pull Request

adding the cir_img() function. Replacing the closed, erroneous PR #250. Alreasy uses RETRY() as discussed in PR #271 .

PR task list:

  • Update NEWS
  • [not appropriate for images?] Add tests (if appropriate)
  • Update documentation with devtools::document()
  • Check package passed

Copy link
Collaborator

@Aariq Aariq left a comment

Choose a reason for hiding this comment

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

Very excited to be adding image functions to webchem! Here are some style suggestions and a couple of issues with the behavior of the function.

R/cir.R Show resolved Hide resolved
R/cir.R Show resolved Hide resolved
R/cir.R Outdated Show resolved Hide resolved
R/cir.R Outdated Show resolved Hide resolved
R/cir.R Outdated Show resolved Hide resolved
R/cir.R Outdated Show resolved Hide resolved
@Aariq
Copy link
Collaborator

Aariq commented Jul 16, 2020

  • [not appropriate for images?] Add tests (if appropriate)

I think it might be good to write some tests to check that error messages work as expected and file downloads happen or don't happen when expected. You can use tempdir() to download images inside tests. I don't think it's necessary to check that the correct image is downloaded.

andschar and others added 2 commits July 16, 2020 17:23
@andschar
Copy link
Contributor Author

  • [not appropriate for images?] Add tests (if appropriate)

I think it might be good to write some tests to check that error messages work as expected and file downloads happen or don't happen when expected. You can use tempdir() to download images inside tests. I don't think it's necessary to check that the correct image is downloaded.

I have added some tests to check the funciton.

@andschar
Copy link
Contributor Author

andschar commented Jul 27, 2020

@Aariq In the update b988a2b I changed the function back to if statements for all the options because some option strings need extra quotation marks, which can't be easily done with your suggestion.

@andschar
Copy link
Contributor Author

to vectorise the function I now use a for loop instead of lapply(). This might sound "un-Rish" at first, however I think in this case it's much better because a for loop doesn't return anything. Hence, if I run a = cir_img('CCO', tempdir()), a will be NULL. If I were to use lapply() I'd receive some sort of list, depending on whether all results return errors or not. Also, to avoid printing something to the console, I'd have to wrap the whole function into invisible().

@Aariq
Copy link
Collaborator

Aariq commented Aug 6, 2020

One more change and I think it'll probably be good to go. It currently has the issue where it mistakes NA for sodium.

>cir_img(NA, here())
Querying NA. OK (HTTP 200). Image saved under: /Users/scottericr/Documents/webchem/NA.png

NA

Copy link
Contributor

@stitam stitam left a comment

Choose a reason for hiding this comment

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

Thanks @andschar for your work on this PR and sorry for the late reply. I agree, this PR is almost there.

R/cir.R Outdated Show resolved Hide resolved
R/cir.R Show resolved Hide resolved
tests/testthat/test-cir.R Show resolved Hide resolved
@andschar
Copy link
Contributor Author

One more change and I think it'll probably be good to go. It currently has the issue where it mistakes NA for sodium.

>cir_img(NA, here())
Querying NA. OK (HTTP 200). Image saved under: /Users/scottericr/Documents/webchem/NA.png

NA

Good point. It's also a problem if somebody would call the function like this cir_img('', tempdir()), because an empty image would be returned. My solution would be the following. Check NAs and empty strings at the start of the function. What do you think? Are there better options?

vec = c(NA, '', 'Triclosan')
if (anyNA(vec) || any(vec == '')) {
  stop('NA or empty strings provided.')
}

R/cir.R Outdated Show resolved Hide resolved
@stitam
Copy link
Contributor

stitam commented Aug 18, 2020

Checks fail because Pubchem is a living database so tests often become outdated. Let's not worry about those tests here. CIR tests work locally.

@Aariq Aariq merged commit 6347eba into ropensci:master Aug 20, 2020
@andschar andschar deleted the dev_cir branch August 20, 2020 15:16
@stitam stitam added this to the RC2019F milestone Sep 5, 2020
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.

3 participants