How to Convert a Factor in R
How to Track Data Correlations in R
How to Take Samples from Data in R

How to Provide the Right Information in an R Minimal Reproducible Example

One of the hardest parts of producing an R minimal reproducible example is to keep it minimal. Another is making sure that you provide the necessary information so your problem is indeed reproducible.

Keep it minimal

The challenge is to identify the smallest example (the fewest lines of code) that reproduces the problem or error. Before you submit your code, make sure to describe clearly which packages you use. In other words, remember to include the library() statements.

Also, test your code in a new, empty R session to make sure it runs without error. People should be able to just copy and paste your data and your code in the console and get exactly the same results as you get.

Provide the necessary information

Including a little bit of information about your R environment helps people answer your questions. You should consider supplying the following:

  • Your R version (for example, R 2.13-1)

  • Your operating system (for example, Windows 7 64-bit)

The function sessionInfo() prints information about your version of R and some locale information, as well as attached or loaded packages. Sometimes the output of this function can help you determine whether there are conflicts between your loaded packages. Here’s an example of the results of sessionInfo():

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats   graphics grDevices utils   datasets
[6] methods  base
other attached packages:
[1] rj_1.0.2-5   devtools_0.5.1
loaded via a namespace (and not attached):
[1] RCurl_1.6-10.1 tools_2.14.1

The results tell you that this session is running R version 2.14 on 64-bit Windows, with a United Kingdom locale. You also can see that R has loaded two packages: package rj (version 1.0.2-5) and package devtools (version 0.5.1).

Sometimes it’s helpful to include the results of sessionInfo() in your question, because other R users can then tell whether there could be an issue with your R installation.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Present Dates in Different Formats in R
How to Do More with Loops in R
How to Perform Multiple Calculations with Vectors Using R
How to Create a Function in R
How to Sort Text Cases in R
Advertisement

Inside Dummies.com