Restrict the number of file names provided in use_r() and use_test()#862
Merged
Conversation
added 4 commits
August 2, 2019 23:12
They try to mimic `check_file_name()` and `valid_file_name()` respectively.
jennybc
reviewed
Aug 5, 2019
| #' Packages](https://r-pkgs.org). | ||
| #' @export | ||
| use_r <- function(name = NULL) { | ||
| check_file_name_length(name) |
Member
There was a problem hiding this comment.
I think it would be pretty self-consistent of us to do something simpler in this case. I propose stopifnot(is_string(name)) instead of a custom helper.
Member
There was a problem hiding this comment.
Also, the check should happen after the name <- name %||% ... line, because NULL input is valid.
Contributor
Author
There was a problem hiding this comment.
I agree all except that we use stopifnot(). A regular if-not-true-stop branch might be more useful to give better error messages for the end-users.
Contributor
Author
There was a problem hiding this comment.
On the other hand, I see that stopifnot(is_string(name)) is often used in the package to check inputs.
As proposed in review, a new helper for checking length of input strings isn't pretty much needed. The `is_string()` call in the utils is convenient. Therefore, the check is moved inside the `check_file_name()` helper which is used both by `use_r()` and `use_test() calls.
Conflicts: NEWS.md
Member
|
Thanks @strboul! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Although it will be quite useful that if we have a way to create multiple files at once - I might use them as stubs and fill them in once I feel ready, it is not so easy to do the implementation at the moment.
So I thought that we can limit these calls that they will stop the execution if a vector provided with which its length is more than one. That limitation is also aligned with the current API of these functions because the main argument either in
use_r()oruse_test()states 'name' (not the plural version 'names').This is my first PR in usethis. I am happy to modify my changes accordingly based on your review.
Resolves #861