Skip to content

add a use case for storing a data frame in a gist, #78 #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion inst/vign/gistr_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ g <- gists()
gist(forked$id) %>% delete()
```

## Example use case
## Example use cases

_Working with the Mapzen Pelias geocoding API_

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

![](img/gistr_ss.png)

_Round-trip storage of a data frame_

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`.

```{r eval=FALSE}
data(iris)

str <- ''
tc <- textConnection('str', 'w', local = TRUE)
write.csv(iris, file = tc, row.names = FALSE)
close(tc)

content <- list(content=paste(as.character(str), collapse='\n'))

gistr::gist_create(code = {
content$content
}, description = "using a gist as a data store",
filename = "iris.csv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put in the output here? so readers can see what it should look like?

e.g. https://github.com/ropensci/gistr/blob/master/inst/vign/gistr_vignette.Rmd#L288-L293

#> <gist>c7dfe593f4944df4818df884689734f9
#> URL: https://gist.github.com/c7dfe593f4944df4818df884689734f9
#> Description: using a gist as a data store
#> Public: TRUE
#> Created/Edited: 2019-07-18T14:23:23Z / 2019-07-18T14:23:23Z
#> Files: iris.csv
#> Truncated?: FALSE

output <- read.csv(
text = gist(gists(what = "minepublic", per_page = 1)[[1]]$id)$
files$iris.csv$content)

identical(output, iris)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

#> TRUE
```