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.

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.

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()
```

Publishing plots

To publish plots, simply call publish:

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

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

# This works, too
hm1 %>% publish("Heatmaps are cool!")

Capturing base graphics

To capture output from base R plotting, call publish with a plotting expression:

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

gofigR::publish({
  # 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.

Shiny

You can replace plotOutput + renderPlot with gfPlot + gfPlotServer and give your users the ability to publish interactive plots to GoFigr. For example:

library(shiny)
library(gofigR)

gofigR::enable()

# Define UI for application that draws a histogram
ui <- fluidPage(
  # Application title
  titlePanel("Old Faithful Geyser Data"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      gfPlot("distPlot"),
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

  gfPlotServer("distPlot", {
    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white',
         xlab = 'Waiting time to next eruption (in mins)',
         main = 'Histogram of waiting times')
  }, input, figure_name="Old faithful waiting times")
}

# Run the application
shinyApp(ui = ui, server = server)

Note that we pass input to gfPlotServer. This will capture your current Shiny inputs – they will become available under the "Metadata" tab in GoFigr.

Interactive use

We support knitr as well as interactive sessions in RStudio.

Common issues

Heatmap functions that draw and return an object (e.g. pheatmap)

Some plotting functions in R both draw to the active graphics device and return an object. A common example is pheatmap::pheatmap(), which immediately draws the heatmap and also returns a "pheatmap" object.

If you use this pattern in an R Markdown document:

pheatmap::pheatmap(mat) %>% publish("My heatmap")

the heatmap is first drawn by pheatmap() (captured by knitr as a regular, non‑GoFigr figure) and then drawn again by publish() (captured with the GoFigr watermark/QR code). This can make the same heatmap appear twice in your output.

To avoid duplication with pheatmap, ask it to return the plot object without drawing, and then pass that object to publish():

hm <- pheatmap::pheatmap(mat, silent = TRUE)  # returns a pheatmap object without drawing
publish(hm, "My heatmap")

This way, only the GoFigr-rendered, watermarked version of the heatmap is shown.

Copy Link

Version

Install

install.packages('gofigR')

Monthly Downloads

214

Version

1.1.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Maciej Pacula

Last Published

November 26th, 2025

Functions in gofigR (1.1.3)

create_revision

Creates a new revision
create_analysis

Create a new analysis within a workspace.
get_options

Gets configured GoFigr options.
gfPlotServer

Creates a Shiny component to handle plotting and publishing. Has to be paired with a gfPlot element in the UI.
get_qr_png

Generates a QR code and converts it into an img element.
gf_plot

Plots and publishes an object (if supported)
find_figure

Find a figure by name within an analysis.
create_workspace

Create a new workspace.
find_workspace

Find a workspace by name, optionally creating it.
find_analysis

Find an analysis by name, optionally creating it.
get_workspace

Retrieve workspace details.
find_asset_by_name

Finds an asset by name
gofigr_cat

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

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

Fetch an analysis by API ID.
get_api_id

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

Gets a title from a plot
get_execution_context

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

Fetch a single figure by API ID.
infer_workspace

Resolve the workspace argument, falling back to the client's default.
gofigr_make_handler

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

Finds all asset revisions with a matching hash digest
get_client

Gets the currently configured GoFigr client
gofigr_POST

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

Retrieves a data object. Use in conjunction with get_revision or get_asset_revision, to retrieve the full data for a data object.
gofigr_PUT

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

Generates a div container for the GoFigr widget.
gfPlot

Defines a GoFigr plot area.
publish_base

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

Publishes a figure to the GoFigr service.
create_api_key

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

Fetches a revision given an API ID.
stack_vertically

Stacks images vertically, centering them horizontally.
stack_horizontally

Stacks images horizontally, centering them vertically.
make_file_data

Creates a GoFigr data object storing file data
read.csv

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
read.csv2

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
make_image_data

Creates a GoFigr data object storing image data
get_revision_url

Gets the full URL for a revision
suppress

Suppresses any automatic GoFigr publication hooks.
list_analyses

List analyses within a workspace.
is_intercept_on

Checks whether GoFigr intercept is on
make_text_data

Creates a GoFigr data object to store text
gf_print

Prints and publishes an object (if supported)
ggwatermark

Applies a watermark to a plot object/function.
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
gofigr_DELETE

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

Creates a new asset revision from file.
sync_file

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
read_csv

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
find_config

Finds the .gofigr config file in current directory or any of the parent directories. If the file cannot be found, will also check CONFIG_PATH.
update_revision_data

Updates data associated with a figure
gofigr_PATCH

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

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

Creates a GoFigr data object storing data.frame/tabular data
print.gofigr

Default print method for a GoFigr client.
print.gofigr_revision

Default print method for GoFigr revisions.
make_raw_data

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

Gets an asset revision given an API ID
read_csv2

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
login_with_api_key

Prompts the user for an API key or interactively creates a new one.
list_workspaces

List all workspaces available to the authenticated user.
watermark_generator

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

Executes an expression while isolating any new graphics devices it creates.
user_info

Fetches user details for the currently logged in user.
read.xlsx

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
login_with_username

Prompts the user for username and password and logs into GoFigr.
response_to_JSON

Convenience function for parsing JSON from httr responses
make_code_data

Creates a GoFigr data object storing source code
gfconfig

Interactive configuration helper for the GoFigr R client.
read_config

Reads the GoFigr configuration, prioritizing environment variables over the config file:
set_options

Sets GoFigr options.
read_tsv

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
read_delim

Syncs a file with the GoFigr service and stores a reference. The file will be associated with all figures published after this call.
read_prompt

Reads a line from stdin with optional validation and retry logic.
try_base2grob

Tries to convert expression to a grob, returning it unchanged if it fails.
sync_workspace_asset

Syncs a file with the GoFigr service
refresh_jwt

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

Draws a watermark with just a GoFigr link
NO_WATERMARK

Does not draw any watermarks.
QR_WATERMARK

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

Creates an object representing a relationship between a figure and an asset.
enable

Enables GoFigr in the current R/Rmd file.
encode_raw_data

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

Creates a new asset revision
create_asset

Creates a new asset
get_asset

Fetches an asset given an API ID.
cat.gofigr_revision

Default cat method for GoFigr revisions.
create_figure

Create a new figure under an analysis.
CONFIG_PATH

Default path to the config file
check_configured

Checks whether GoFigr has been correctly configured.
default_if_null

Returns a default value if argument is null or empty
delete_analysis

Delete an analysis by API ID.
DATA_TYPES

List of data types supported by GoFigr
authenticate_jwt

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

Calculates a checksum for a file
create_ggsave_args

Creates a list of arguments for ggplot2::ggsave() with optional dimension and DPI parameters.