-
Notifications
You must be signed in to change notification settings - Fork 286
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
Improvements to standalone header #1903
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac416f3
Add ref and host to standalone header
krlmlr 1fa63fd
Add code to generate the standalone
krlmlr f547df7
Merge branch 'main' into f-standalone-code
jennybc 6e37a77
Make some more changes
jennybc afdaded
Dogfood it
jennybc 9fc6457
Add NEWS bullet
jennybc 4cd2e6c
Use fs
jennybc 0d32cfa
Update a snapshot
jennybc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ use_standalone <- function(repo_spec, file = NULL, ref = NULL, host = NULL) { | |
dest_path <- path("R", as_standalone_dest_file(file)) | ||
|
||
lines <- read_github_file(repo_spec, path = src_path, ref = ref, host = host) | ||
lines <- c(standalone_header(repo_spec, src_path), lines) | ||
lines <- c(standalone_header(repo_spec, src_path, ref, host), lines) | ||
write_over(proj_path(dest_path), lines, overwrite = TRUE) | ||
|
||
dependencies <- standalone_dependencies(lines, path) | ||
|
@@ -156,10 +156,22 @@ as_standalone_dest_file <- function(file) { | |
gsub("standalone-", "import-standalone-", file) | ||
} | ||
|
||
standalone_header <- function(repo_spec, path) { | ||
standalone_header <- function(repo_spec, path, ref = NULL, host = NULL) { | ||
ref_string <- ref %||% "HEAD" | ||
host_string <- host %||% "https://github.com" | ||
source_comment <- | ||
glue("# Source: {host_string}/{repo_spec}/blob/{ref_string}/{path}") | ||
|
||
path_string <- path_ext_remove(sub("^standalone-", "", path_file(path))) | ||
ref_string <- if (is.null(ref)) "" else glue(', ref = "{ref}"') | ||
host_string <- if (is.null(host) || host == "https://github.com") "" else glue(', host = "{host}"') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only include |
||
code_hint <- glue('usethis::use_standalone("{repo_spec}", "{path_string}"{ref_string}{host_string})') | ||
generated_comment <- glue('# Generated by: {code_hint}') | ||
|
||
c( | ||
"# Standalone file: do not edit by hand", | ||
glue("# Source: <https://github.com/{repo_spec}/blob/main/{path}>"), | ||
source_comment, | ||
generated_comment, | ||
paste0("# ", strrep("-", 72 - 2)), | ||
"#" | ||
) | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works better in Positron to not surround this with
<>
, i.e. the automatic hyperlink detection copes better with this form.