Please see the matahari website for full documentation:

library(matahari)

There are three ways to use the matahari package

  1. Record R code as it is typed and output a tidy data frame of the contents
  2. Input a character string of R code and output a tidy data frame of the contents
  3. Input an R file containing R code and output a tidy data frame of the contents

This vignette will walk through how to do each of these tasks.

Record R code as it is typed

To record R code as it is typed, use the dance_start() and dance_stop() functions.

Each time dance_start() is run, a data frame logging the subsequent code is updated. To start over with a new data frame, you can use dance_remove() and then re-run dance_start().

By default, this just records the R calls typed into the R console, populating the expr column of the data frame. You can optionally also record the following by setting the parameter of the name to TRUE. Some of these rely on using RStudio as your IDE.

  • value: The values that are computed
  • path: The path to the file in focus on the RStudio editor
  • contents: The file contents of the RStudio editor tab in focus
  • selection: The text that is highlighted in the RStudio editor tab in focus

For example, the same code with value = TRUE results in the following tidy data frame.

Notice now the value column is now populated.

Input a character string of R code

Alternatively you can input a string of R code and output a tidy data frame, using the dance_recital() function.

This creates the same expr and value columns as the dance_start() dance_stop() workflow described above. In addition, it outputs any errors, output, warnings, or messages generated by the R code in the character string. Notice this data frame does not have the session information, since it is not called interactively from the R console. By default, dance_recital() will evaluate all R code passed to it to retrieve the value column. If you would like to just output the expr column, you can set evaluate = FALSE. This may be especially useful if you are analyzing lots of code and it would take a long time to run all commands.