safe_get_content: Safely download and parse web content

View source: R/data_generation.R

safe_get_contentR Documentation

Safely download and parse web content

Description

This helper function retrieves content from a given URL using httr. It ensures that common issues (e.g. no internet, timeouts, HTTP errors, or parsing errors) are handled gracefully with clear, informative error messages.

Usage

safe_get_content(url, ..., timeout_sec = 10)

Arguments

url

Character string. The URL of the resource to download.

...

Additional arguments passed to GET.

timeout_sec

Numeric. Timeout in seconds for the request (default = 10).

Details

This function is intended for use inside package functions. For examples, vignettes, or tests, wrap calls in a connectivity check (e.g. using http_error(HEAD(url))) to avoid CRAN failures when the resource is temporarily unavailable.

Value

A character string containing the parsed content of the response (UTF-8 encoded). On failure, an error is raised with a clear message.

Examples

## Not run: 
# Retrieve the latest BioGRID release page
result <- safe_get_content("https://downloads.thebiogrid.org/BioGRID/Latest-Release/")

## End(Not run)


pathfindR documentation built on Nov. 5, 2025, 5:59 p.m.