Yes, the trick is that the data referenced in the reprex has to be available within the reprex. Since Jobsatisfaction is data that you created, R can't reference it unless we create it. The tribble function that @mara mentioned is a pretty straightforward way of doing it. When I previously mentioned dput, the idea with that is that you would use that to generate code that you can paste into a script.
Say I wanted the first 5 rows of the iris data (since it's also good to minimize how much data you include in a reprex). It's a built-in data set, but if it wasn't, I could do something like this:
> dput(head(iris, 5))
structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5), Sepal.Width = c(3.5,
3, 3.2, 3.1, 3.6), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4),
Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2), Species = structure(c(1L,
1L, 1L, 1L, 1L), .Label = c("setosa", "versicolor", "virginica"
), class = "factor")), .Names = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width", "Species"), row.names = c(NA,
5L), class = "data.frame")
>
I would then copy and paste the entire structure into the code for my reprex, assigning it to a variable.
my_iris <- structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5), Sepal.Width = c(3.5,
3, 3.2, 3.1, 3.6), Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4),
Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2), Species = structure(c(1L,
1L, 1L, 1L, 1L), .Label = c("setosa", "versicolor", "virginica"
), class = "factor")), .Names = c("Sepal.Length", "Sepal.Width",
"Petal.Length", "Petal.Width", "Species"), row.names = c(NA,
5L), class = "data.frame")
I could then reference my_iris in the code, and someone else using the code would have the same data that I did.