Build Status Coverage status

CRAN_Status_Badge RStudio CRAN downloadsRStudio CRAN monthly downloadsRdocumentation

Project Status: Active – The project has reached a stable, usable state and is being actively developed. lifecycle



  • Rclean was created to help scientists more easily write “cleaner” code.
  • Written with research scientists that are results oriented in mind, the package’s primary function provides a simple way to isolate the minimal code you need to produce a specific result, such as a statistical table or a figure. By focusing on specific results (aka. variables), large and/or complicated analytical scripts can be paired down to the essentials and easily re-factored to be more robust and easily shared.
  • Below, you’ll find a brief introduction to get you started using the package. For more details, see vignette("Rclean").


You can install the most up to date version easily with devtools:

You will also likely need to install the RGraphViz:

Once installed, per usual R practice just load the Rclean package with:


Rclean usage is simple. Have a script with code you want to clean saved to disk. Then, just run the clean function with the path to the script as the input. Here, we can use an example script that is included with the package:

Here’s a quick look at the code:

You can get a list of the variables found in an object with get_vars.

Sometimes for more complicated scripts, it can be helpful to see a network graph showing the interdependencies of variables. code_graph will produce a network diagram showing which lines of code produce or use which variables:

Now, we can pick the result we want to focus on for cleaning:

We can also select several variables at the same time:

While just taking a look at the simplified code can be very helpful, you can also save the code for later use or sharing (e.g. creating a reproducible example for getting help) with keep:

If you would like to copy your code to your clipboard, you can do that by not specifying a file path. You can now paste the simplified as needed.


This is an open-source project. If you would like to contribute to the project, please check out

Please note that the ‘Rclean’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.