This function fetches a file from a GitHub repository and returns its content and SHA. If the file cannot be retrieved, it returns NULL and optionally displays a warning message.
Value
When successful, returns a list
with two elements:
- content
Character string containing the decoded file content
- sha
Character string with the file's blob SHA for use in update operations
When the file cannot be retrieved (e.g., does not exist or no access), returns NULL
.
Examples
if (FALSE) { # interactive()
# Get content from default branch
file_info <- file_content("username/repository", "path/to/file.R")
if (!is.null(file_info)) {
# Access the content and SHA
content <- file_info$content
sha <- file_info$sha
}
# Get content from specific branch
file_info <- file_content("username/repository", "path/to/file.R", ref = "develop")
# Suppress warnings
file_info <- file_content("username/repository", "path/to/file.R")
}