Skip to content

Restrict the number of file names provided in use_r() and use_test()#862

Merged
hadley merged 9 commits into
r-lib:masterfrom
strboul:861-limit-multiple-names
Oct 16, 2019
Merged

Restrict the number of file names provided in use_r() and use_test()#862
hadley merged 9 commits into
r-lib:masterfrom
strboul:861-limit-multiple-names

Conversation

@strboul
Copy link
Copy Markdown
Contributor

@strboul strboul commented Aug 2, 2019

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() or use_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

Comment thread R/r.R Outdated
#' Packages](https://r-pkgs.org).
#' @export
use_r <- function(name = NULL) {
check_file_name_length(name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, the check should happen after the name <- name %||% ... line, because NULL input is valid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On the other hand, I see that stopifnot(is_string(name)) is often used in the package to check inputs.

Comment thread tests/testthat/test-use-r.R Outdated
Comment thread R/test.R Outdated
Metin Yazici and others added 5 commits August 6, 2019 22:36
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.
@hadley hadley merged commit 3996db9 into r-lib:master Oct 16, 2019
@hadley
Copy link
Copy Markdown
Member

hadley commented Oct 16, 2019

Thanks @strboul!

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.

use_r() and use_test() fail when multiple names are provided in the name argument

3 participants