Rmarkdown does not show proper output after Knit

I'm knitting below into html with an issue of the html output not corresponding to the console.

#reading packages..all good
install.packages('devtools', repos = 'http://cran.us.r-project.org') 
devtools::install_github('xuyiqing/gsynth')
library(foreign)
library(gsynth)

But there's an issue when it comes to loading a data set from one of the packages. It does get loaded, but my html output shows :

data(gsynth)
## Warning in data(gsynth): data set 'gsynth' not found

Any solution appreciated.

Your call to data doesn’t work because the gsynth package doesn’t have a data set called “gsynth”, instead its data set is called “simdata”. But if you’ve loaded the package, any included data sets are already available to you without invoking data** — in fact, it’s usually undesirable to do so. You can read more about this in the “Good Practice” section of the documentation for data.

A common problem is that you’ve created an object interactively (or while testing a previous iteration of your code) and it’s lingering in your global environment even though the code in the file you’re knitting doesn’t actually successfully create that object.

In these situations, restarting your R session and clearing your global environment before running your code at the console will reveal the ugly truth :fearful: — but you may need to pick through your R history to figure out how to capture in your script the steps you took to create those lingering :ghost: objects.


** To convince yourself this is true, in a fresh R session with an empty global environment, try:

library(ggplot2)
head(diamonds)
2 Likes