Learn R Programming

gofigR

gofigR is the R client for https://gofigr.io, a zero-effort reproducibility engine. It works with any R library which outputs to R graphics devices, with automatic publishing for ggplot.

Compatibility

gofigR integrates with R markdown, both in knitr and in interactive sessions in RStudio. GoFigr also works in scripts. We tested with R 4.3.2 but any reasonably recent version should work.

GoFigr will automatically publish all ggplot output assuming you call gofigR::enable(auto_publish=TRUE). GoFigr will not publish old-style R plots unless you tell it to. See the "Usage" section below.

Installation

library(devtools)
devtools::install_github("gofigr/gofigR")

Configuration

On the R prompt, simply load the gofigR package and call gfconfig(). You only need to do this once.

If you don't have an account, you can register at https://app.gofigr.io/register.

> library(gofigR)
Attaching package: ‘gofigR’

> gfconfig()
-------------------------------------------------------------------

Welcome to GoFigr! This wizard will help you get up and running.

-------------------------------------------------------------------


Username: publicdemo
Testing connection...

  => Success

API key (leave blank to generate a new one): 
Key name (e.g. Alyssa's laptop): my API key
Fetching workspaces...

1. Scratchpad - e5249bed-40f0-4336-9bd3-fef30d3ed10d

Please select a default workspace (1-1): 1

Configuration saved to /Users/maciej/.gofigr. Happy analysis!

Usage

To enable GoFigr, simply call enable in your setup chunk. You can also optionally specify an analysis_name (it will be created automatically if it doesn't exist).

```{r setup, include=FALSE}
library(gofigR)
gofigR::enable(auto_publish=TRUE)
```

auto_publish is FALSE by default. Set it to TRUE to override plot and print and publish figures automatically.

Automatic output capture

If auto_publish is on, GoFigr will intercept all calls to plot and print and publish the results if they are from a compatible library. At the moment, we support any graphics format also supported by ggplotify:

  • ggplot2

  • ComplexHeatmap

  • cowplot

  • patchwork

  • lattice

Manual capture

To capture output manually, simply call publish:

hm1 <- Heatmap(matrix(rnorm(100), nrow=10, ncol=10))

publish(hm1, "Heatmaps are cool!")  # second argument is the figure name

Capturing base graphics

To capture output from base R plotting, call publish_base:

gofigR::publish_base({
  base::plot(pressure, main="Pressure vs temperature")
  text(200, 50, "Note the non-linear relationship")
}, data=pressure, figure_name="Pressure vs temperature")

gofigR::publish_base({
  # The mtcars dataset:
  data <- as.matrix(mtcars)

  coul <- colorRampPalette(brewer.pal(8, "PiYG"))(25)
  heatmap(data, scale="column", col = coul, main="Visualizing mtcars")
}, data=mtcars, figure_name="Cars")

Note the optional data argument following the expression. It specifies the data which you want to associate with the figure -- it will show up under "files" (as .RDS) once published.

Interactive use

We support knitr as well as interactive sessions in RStudio.

Copy Link

Version

Install

install.packages('gofigR')

Monthly Downloads

184

Version

0.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Maciej Pacula

Last Published

March 19th, 2025

Functions in gofigR (0.3.1)

encode_raw_data

Converts a GoFigr data object into R primitives that can be converted to JSON, performing base64 encoding of binary data.
find_analysis

Finds an analysis by name, optionally creating one if it doesn't exist.
get_analysis

Fetches an analysis given an API ID.
enable

Enables GoFigr support.
find_workspace

Finds a workspace by name, optionally creating it if doesn't exist
find_figure

Finds a figure by name
create_workspace

Creates a new workspace
get_execution_context

Gets the execution context: input path, chunk code, and other metadata.
intercept

Wraps a plotting function (e.g. plot) so that its output is intercepted by GoFigr.
is_expired_token

Returns True if the response indicates an expired JWT token
get_revision_url

Gets the full URL for a revision
get_title

Gets a title from a plot
make_code_data

Creates a GoFigr data object storing source code
gofigr_cat

Equivalent to cat but only outputs if GoFigr client is verbose.
login_with_username

Prompts the user for username & password and logs into GoFigr
gofigr_client

Creates and configures a GoFigr client. You can login either using a username & password or an API key. See examples.
gofigr_make_handler

Wraps an HTTR method e.g. GET to provide relative URL resolution and authentication
gf_plot

Plots and publishes an object (if supported)
get_workspace

Retrieves workspace details.
get_revision

Fetches a revision given an API ID.
get_options

Gets configured GoFigr options.
gofigr_GET

Wrapper for httr::GET that automatically handles authentication.
gf_print

Prints and publishes an object (if supported)
refresh_jwt

Refreshes the JWT access token. Attempts re-authentication if refresh fails.
watermark_generator

Makes a watermark generator. You can use the result with enable(watermark=...).
gofigr_PATCH

Wrapper for httr::PATCH that automatically handles authentication.
read_prompt

Reads a prompt from stdin and performs optional validation
user_info

Fetches user details for the currently logged in user.
get_figure

Fetches a figure given an API ID.
make_table_data

Creates a GoFigr data object storing data.frame/tabular data
stack_vertically

Stacks images vertically, centering them horizontally.
make_raw_data

Creates a GoFigr data object which can be attached to revisions.
stack_horizontally

Stacks images horizontally, centering them vertically.
gfconfig

Configures gofigr for use on this machine. Saves configuration to ~/.gofigr.
gofigr_POST

Wrapper for httr::POST that automatically handles authentication.
gofigr_PUT

Wrapper for httr::PUT that automatically handles authentication.
ggwatermark

Applies a watermark to a plot object/function.
make_file_data

Creates a GoFigr data object storing file data
make_image_data

Creates a GoFigr data object storing image data
print.gofigrdata

Default print representation of GoFigr data objects.
infer_workspace

Returns the argument if a valid workspace is passed, or the default workspace from the GoFigr client otherwise. Throws an error if both are NULL.
suppress

Suppresses any automatic GoFigr publication hooks.
publish

Publishes a figure to the GoFigr service.
update_revision_data

Updates data associated with a figure
list_workspaces

List all workspaces available to the user.
list_analyses

Lists analyses under a workspace.
is_intercept_on

Checks whether GoFigr intercept is on
make_text_data

Creates a GoFigr data object to store text
gofigr_DELETE

Wrapper for httr::DELETE that automatically handles authentication.
publish_base

Captures output from grid graphics (ggplot2, lattice, ComplexHeatmap, etc.) and publishes it to GoFigr.
login_with_api_key

Prompts the user for an API key or creates a new one
response_to_JSON

Convenience function for parsing JSON from httr responses
read_config

Reads the GoFigr configuration, prioritizing environment variables over the config file:
print.gofigr

Default print method for a GoFigr client.
set_options

Sets GoFigr options.
check_configured

Checks whether GoFigr has been correctly configured.
LINK_WATERMARK

Draws a watermark with just a GoFigr link
CONFIG_PATH

Default path for the config file
create_figure

Creates a new figure. The created figure will be blank and won't contain any revisions.
DATA_TYPES

List of data types supported by GoFigr
NO_WATERMARK

Does not draw any watermarks.
create_analysis

Creates a new analysis
authenticate_jwt

Performs JWT authentication with username and password. Saves tokens in the GoFigr client.
QR_WATERMARK

Draws a watermark with a GoFigr link and a QR code
get_api_id

Returns obj$api_id if argument is an object, or identity if it's a string.
default_if_null

Returns a default value if argument is null or empty
create_api_key

Creates a new API key. This function will only succeed if using password authentication.
create_revision

Creates a new revision