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

Create a function download_models to download ss3 test models #721

Merged
merged 5 commits into from Jul 29, 2022

Conversation

k-doering-NOAA
Copy link
Contributor

Resolves #574 by creating a download_models() function that will download the models subfolder from the nmfs-stock-synthesis/test-models repository. There is an option to specify which branch to download and which directory to write to.

I requested @kellijohnson-NOAA to review as I think this was her idea, but feel free to reassign to @iantaylor-NOAA instead if you are too busy.

This test would fail if the super_test feature branch is removed from the test-models repo, so it seems wise to not include it. However, it was a nice local test to make sure the function worked as I expected when setting it up!
@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #721 (eab0822) into main (b03e4d0) will decrease coverage by 2.95%.
The diff coverage is 47.24%.

❗ Current head eab0822 differs from pull request most recent head f409bae. Consider uploading reports for the commit f409bae to get more accurate results

@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
- Coverage   54.88%   51.93%   -2.96%     
==========================================
  Files         111      111              
  Lines       25975    25985      +10     
==========================================
- Hits        14257    13495     -762     
- Misses      11718    12490     +772     
Impacted Files Coverage Δ
R/NegLogInt_Fn.R 0.00% <0.00%> (ø)
R/RebuildPlot.R 0.00% <0.00%> (ø)
R/SSMethod.Cond.TA1.8.R 0.00% <0.00%> (ø)
R/SS_ForeCatch.R 0.00% <0.00%> (ø)
R/SS_readctl.R 53.06% <ø> (-32.66%) ⬇️
R/SS_readctl_3.24.R 0.00% <0.00%> (-49.33%) ⬇️
R/SS_readctl_3.30.R 69.93% <ø> (ø)
R/SS_readdat_2.00.R 0.00% <0.00%> (ø)
R/SS_readdat_3.00.R 0.00% <0.00%> (ø)
R/SS_readdat_3.24.R 0.00% <0.00%> (-58.26%) ⬇️
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c0be74...f409bae. Read the comment docs.

Copy link
Contributor

@kellijohnson-NOAA kellijohnson-NOAA left a comment

Choose a reason for hiding this comment

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

@k-doering-NOAA thanks for writing this function. It works great. I tested it out on my local machine but I did not run the tests. GitHub actions is enough for me there 😉

Feel free to ignore all of the nit picky comments. But, there is one substantial design-choice that I am not sure that I agree with. Instead of just stopping if dir doesn't exist cannot we create dir recursively at the start of the function?

R/download_models.R Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
R/download_models.R Outdated Show resolved Hide resolved
tests/testthat/test-download_models.R Outdated Show resolved Hide resolved
tests/testthat/test-download_models.R Outdated Show resolved Hide resolved
@k-doering-NOAA
Copy link
Contributor Author

Thanks @kellijohnson-NOAA for the comments! I'll go over them later today or early next week.

I was just reading the ropen sci blog post and wanted to drop a link on this thread; when I was developing the testthat tests for download_models(), I tried to use tempdir() directly and it was a disaster! Apparently what you want to do is create a subdirectory within tempdir to do your testing, which is the approach I arrived at by trial and error, so it is good to see this advice reflected elsewhere as the best practice to use: https://ropensci.org/blog/2022/01/31/package-build-failures/#whacky-use-of-temporary-directories

including running devtools::spell_check() devtools::document() and styler::style_file() for the files related to download_models
@kellijohnson-NOAA
Copy link
Contributor

@k-doering-NOAA sorry for this late comment but did you look at {usethis} for working with zip files, see here?

@k-doering-NOAA
Copy link
Contributor Author

Aww, I didn't know about this! I actually looked at usethis, because there is a function that can download a file from github, but I didn't know about usethis::use_zip !

Do you think I should modify the PR? The plus of what I wrote is that we don't need to add usethis as a dependency to r4ss, but I can change the code if you would prefer!

@kellijohnson-NOAA
Copy link
Contributor

I think @iantaylor-NOAA should decide if we want another dependency or not. But, I like that usethis in theory provides the checks rather than us having to write them and it ensures that the correct files are closed. Leaving the code is fine. The benefit of using {usethis} is that it is easier for people to copy the single function into their own code and use it or for us to reuse it later. Not sure if that is going to be a thing here though.

@iantaylor-NOAA
Copy link
Contributor

I think making use of the {usethis} function makes sense if it's not too much work to revise all the work that @k-doering-NOAA already put into this. There's nothing about downloading zip files that will ever be unique to {r4ss}, so I'm happy to avoid maintaining custom code when we can share what others are doing and focus on the unique parts of pointing to the model files that we want to download.

I've also come to see a difference between depending on less common packages with questionable maintenance (like {gtools} as discussed in ss3sim/ss3sim#383) vs those that have the full weight of the paid RStudio (now Posit: https://posit.co/) staff maintaining them. The {usethis} package seems genuinely useful so nudging {r4ss} users who don't yet have it installed to do so might improve their lives in other ways.

@k-doering-NOAA
Copy link
Contributor Author

I looked a little more into usethis::use_zip() and think it is more for interactive use, as it always asks the user if they want to delete the .zip file or not (I wasn't sure how to suppress this). Given this, and the fact that we will still need some code to delete all files besides the models subfolder, I think leaving this PR as-is makes the most sense. This can be merged in if Ian and/or Kelli agree!

@kellijohnson-NOAA
Copy link
Contributor

Thanks for checking @k-doering-NOAA into {usethis}. I think that instead of suppressing the warning we could ask {usethis} in the future to remove the interactive nature of the function if we ever did want to change. But, I agree that the code that you wrote is a better solution for now given the other one-off file management that must occur. Sorry for the 🐰 hole.

@k-doering-NOAA
Copy link
Contributor Author

Good idea re: a feature request! Also, the function looks useful for instructing folks on how to download a github repo without needing to clone, so it was definitely worth the time looking into it!

@k-doering-NOAA k-doering-NOAA merged commit 11c2c24 into main Jul 29, 2022
@k-doering-NOAA k-doering-NOAA deleted the issue_574 branch July 29, 2022 15:47
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.

Create function to download "models" directory and provide documentation
3 participants