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

Allow orderly_shared_resource to be used with unnamed arguments. #136

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Apr 10, 2024

The previous behaviour was inconsistent with orderly_resource and often redundant, as users commonly want to copy the resource using the same name as the original file.

It is now possible to use orderly_shared_resource("foo.txt"), in which case the source and destination name are assumed to be the same.

The old syntax is still available in case the user wants to change the name while copying, and it is even possible to mix-and-match, renaming some files but not others.

@plietar plietar requested a review from richfitz April 10, 2024 14:18
The previous behaviour was inconsistent with orderly_resource and often
redundant, as users commonly want to copy the resource using the same
name as the original file.

It is now possible to use `orderly_shared_resource("foo.txt")`, in which
case the source and destination name are assumed to be the same.

The old syntax is still available in case the user wants to change the
name while copying, and it is even possible to mix-and-match, renaming
some files but not others.
R/metadata.R Outdated
validate_shared_resource <- function(args, call) {
if (length(args) == 0) {
cli::cli_abort("'orderly_shared_resource' requires at least one argument",
call = call)
}
assert_named(args, unique = TRUE, call = environment())

Copy link
Member

Choose a reason for hiding this comment

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

Can you see if you can harmonise this through validate_file_from_to (in outpack_misc.R) which contains most of this logic? I think it should just drop in directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha yes. I hadn't noticed that function. Switched to using it.

We now get string interpolation on the filenames "for free". I'm not sure whether it makes much sense to support it. I could disable it easily by setting envir = rlang::empty_env() in the call to validate_file_from_to.

I'm even sure the interpolation is that useful in orderly_dependency / orderly_copy_files. As far as I can tell, it only expands the names, not the values. This means orderly_dependency(..., files = "${foo}") wouldn't work, because it would use the literal ${foo} as the source file name... We could fix that behaviour, or we could remove that feature entirely (is there any benefit in us doing the interpolation? Why can't the caller use sprintf?)

"All elements of 'arguments to 'orderly_shared_resource'' must be strings")
expect_error(
orderly_shared_resource(a = 1, TRUE, "str"),
"All elements of 'arguments to 'orderly_shared_resource'' must be strings")
Copy link
Member Author

@plietar plietar Apr 16, 2024

Choose a reason for hiding this comment

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

These messages are pretty terrible, but I couldn't find a way to deparse the ... reliably so I've just used a placeholder instead.

I'd almost be tempted to change orderly_shared_resource to accept a single files argument instead, making it consistent with all the other functions, including orderly_dependency, orderly_copy_files and orderly_resource, and would make the deparsing easy, but of course that's a breaking change.

@richfitz richfitz merged commit 1a77601 into main Apr 24, 2024
9 checks passed
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.

2 participants