Learn R Programming

multideploy (version 0.1.0)

file_content: Retrieve the content of a file from a GitHub repository

Description

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.

Usage

file_content(repo, path, ref = NULL)

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.

Arguments

repo

Character string specifying the full name of the repository (format: "owner/repo")

path

Character string specifying the path to the file within the repository

ref

Character string specifying the branch name, tag, or commit SHA. Default is NULL (uses default branch).

Examples

Run this code
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")
}

Run the code above in your browser using DataLab