Skip to content

Commit b90fd07

Browse files
jstasckott
authored andcommitted
add a use case for storing a data frame in a gist, #78
1 parent f6aa2e0 commit b90fd07

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

inst/vign/gistr_vignette.Rmd

+27-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ g <- gists()
273273
gist(forked$id) %>% delete()
274274
```
275275

276-
## Example use case
276+
## Example use cases
277277

278278
_Working with the Mapzen Pelias geocoding API_
279279

@@ -296,3 +296,29 @@ gist_create(code = json, filename = "pelias_test.geojson")
296296
And here's that gist: [https://gist.github.com/sckott/017214637bcfeb198070](https://gist.github.com/sckott/017214637bcfeb198070)
297297

298298
![](img/gistr_ss.png)
299+
300+
_Round-trip storage of a data frame_
301+
302+
Maybe you want to use a gist to share some data as an alternative to `dput`? We can do this by writing our `data.frame` to a temporary buffer and passing it to `gist_create`. We can read the data back from the gist by passing its content to `read.csv`.
303+
304+
```{r eval=FALSE}
305+
data(iris)
306+
307+
str <- ''
308+
tc <- textConnection('str', 'w', local = TRUE)
309+
write.csv(iris, file = tc, row.names = FALSE)
310+
close(tc)
311+
312+
content <- list(content=paste(as.character(str), collapse='\n'))
313+
314+
gistr::gist_create(code = {
315+
content$content
316+
}, description = "using a gist as a data store",
317+
filename = "iris.csv")
318+
319+
output <- read.csv(
320+
text = gist(gists(what = "minepublic", per_page = 1)[[1]]$id)$
321+
files$iris.csv$content)
322+
323+
identical(output, iris)
324+
```

0 commit comments

Comments
 (0)