Giter VIP home page Giter VIP logo

gistr's Introduction

gistr

R-CMD-check cran checks codecov.io rstudio mirror downloads cran version

gistr is a light interface to GitHub’s gists for R.

Get started with the docs: https://docs.ropensci.org/gistr

See also:

  • git2r an R client for the libgit2 C library by Stefan Widgren
  • gert Simple git client for R by Jeroen Ooms
  • gistfo for turning your untitled RStudio tabs into gists!

Install

Stable version from CRAN

install.packages("gistr")

Or dev version from GitHub.

remotes::install_github("ropensci/gistr")
library("gistr")
#> 
#> Attaching package: 'gistr'
#> The following objects are masked from 'package:stats':
#> 
#>     embed, update

Meta

  • Please report any issues or bugs.
  • License: MIT
  • Get citation information for gistr in R doing citation(package = 'gistr')
  • Please note that this package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

gistr's People

Contributors

benmarwick avatar cpsievert avatar jsta avatar karthik avatar lmullen avatar maelle avatar romainfrancois avatar sboysel avatar scientificprogrammer avatar sckott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gistr's Issues

Finish off gist_create_obj

  • allow passing in file name, e.g., for geojson, need to have geojson name to render as geojson
  • export all extensions

Deal with truncation

https://developer.github.com/v3/gists/#truncation

Applies for GET requests. if files too large, they are truncated, and only part of the file given back, and a field truncated: TRUE. Here's the bit on truncation:

The Gist API provides up to one megabyte of content for each file in the gist. Every call to retrieve a gist through the API has a key called truncated. If truncated is true, the file is too large and only a portion of the contents were returned in content. If you need the full contents of the file, you can make a GET request to the URL specified by raw_url. Be aware that for files larger than ten megabytes, you’ll need to clone the gist via the URL provided by git_pull_url.

Does this work okay?

@cpsievert @jennybc @karthik @cboettig if you get a second, could you test out the git functionality (vs. using the github http api)?

devtools::install_github("ropensci/gistr@git2r")
library("gistr")
... # do stuff

see examples https://github.com/ropensci/gistr/blob/git2r/R/gist_create_git.R#L7-L29

in the git2r branch we're using git2r to push to a gist (not a github repo), since gists are git repos just as github repos are. This what mbostocks gistup node.js CLI tool does, using git instead of the http api.

p.s. maybe I should add git functionality to gist_create()

Simple usage question

What's the easiest path to get this Gist into my hands using gistr?

https://gist.github.com/expersso/4ac33b9c00751fddc7f8#file-google_maps_with_rvest

I tried this

> browse("https://gist.github.com/expersso/4ac33b9c00751fddc7f8#file-google_maps_with_rvest")
Error: Not Found

I'd like to fork it or get that code on my clipboard or get in a local file. It's just an example of wanting to get someone else's Gist and play with it.

Needless to say, I think this is just a documentation gap. And I obviously know how to complete the task other ways, just thought I'd try to do it with gistr for kicks.

client error: (422) Unprocessable Entity (WebDAV; RFC 4918)

Sorry this isn't really a minimal example, but I'm not sure of a good way to reduce it:

library(git2r)
library(gistr)
repo <- clone("https://github.com/cpsievert/AnimintTest.git", "AnimintTest")
fs <- dir("AnimintTest/FluView", full.names = TRUE)
gist_create(fs, description = "FluView")
#> Error in list2gist(x) : Not coerceable to a gist
#> In addition: Warning message:
#>   In process(response) :
#>   client error: (422) Unprocessable Entity (WebDAV; RFC 4918)

Gist create 405 error with some files

On gist_create() with large files, at least 1.9 MB or larger (the one I found this on), github api returns a 405 - Method not allowed and html error body

But the same file I can paste into browser to create a gist.

And same file uploaded to make a gist using an npm cli tool works fine too - but they use git, not the http api, so not a fair comparison

Weird, maybe it's something going on with httr

Allow passing in an R object to gist_create

Either coerce all objects to json - then when pulled down, jsonlite can convert them back to R objects,

OR

some objects can convert to markdown, like data.frame/matrix to a markdown table

gist_create(file, knit = TRUE, source = TRUE) should work for an R script

Riffing on this example from gist_create():

file <- system.file("examples", "stuff.Rmd", package = "gistr")
gist_create(file, knit=TRUE, include_source=TRUE)

I define an R script like so:

my_code <-"
#' ---
#' output: md_document
#' ---

#' I shall generate random numbers.
x <- rnorm(1000)

#' And I shall summarize them.
summary(x)"
#EDITED LATER! commenting out my initial garbled code and inserting what I meant :(
#my_code_file <- writeLines(my_code, file.path("~", "tmp", "foo.R"))
my_code_file <- file.path("~", "tmp", "foo.R")
writeLines(my_code, my_code_file)

and I would expect something like this to work:

gist_create(my_code_file, description = "My first R code gist via gistr",
            knit = TRUE, include_source = TRUE)

But instead I get this:

> gist_create(my_code_file, description = "My first R code gist via gistr",
+             knit = TRUE, include_source = TRUE)
Error in readLines(if (is.character(input2)) { : 
  object 'input2' not found

Same result if I remove the YAML front matter, so that's not the problem.

param to upload images

Suggest users use imgur, or they could toggle parameter to inject imgur code into .rmd file

Rename edit to update?

When I do something like this:

gists(what = "minepublic")[[1]] %>%   add_files("some_file.R") %>% edit

my action is mostly updating the gist itself. So shouldn't the verb be update instead of edit?

posting a PNG?

I would like to post a PNG to a gist but I am getting the following error

> gist_create("/tmp/RtmpQZytoH/file2f9877e26e34/thumbnail.png")
Loading required package: rjson
Error in content(response)$html_url (from gist.R#78) : 
  $ operator is invalid for atomic vectors
In addition: Warning messages:
1: client error: (400) Bad Request 
2: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘rjson’

the image I tried to upload is below -- I uploaded it using git clone, git add, git commit, git push .

https://gist.githubusercontent.com/tdhock/1f01f3359f60582a67cf/raw/19504d4bdf7daa8bdec14868723ef88ded794d79/thumbnail.png

also I can upload lots of other files (text files). Is there some problem with uploading binary files?

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] graphics  utils     datasets  grDevices stats     methods   base     

other attached packages:
 [1] RSelenium_1.3.1    XML_3.98-1.1       caTools_1.16       gistr_0.0.2       
 [5] animint_2014.5.22  proto_0.3-10       RColorBrewer_1.0-5 lattice_0.20-29   
 [9] plotly_0.4         ggplot2_0.9.3.1.99 RJSONIO_1.0-3      RCurl_1.95-4.1    
[13] bitops_1.0-6      

loaded via a namespace (and not attached):
 [1] assertthat_0.1   colorspace_1.2-4 compiler_3.1.0   dichromat_2.0-0 
 [5] digest_0.6.4     evaluate_0.5.5   formatR_0.10     grid_3.1.0      
 [9] gtable_0.1.2     httr_0.2         knitr_1.5.34     labeling_0.2    
[13] MASS_7.3-31      munsell_0.4.2    plyr_1.8.1       Rcpp_0.11.1     
[17] reshape2_1.2.2   scales_0.2.3     stringr_0.6.2    tools_3.1.0     

Allow knitting file with `edit()`, or knit as separate step

Right now, running code is only in gist_create(), but not avail if you want to edit an existing gist.

Allow knitting on an update in edit():

gists('minepublic')[[1]] %>% edit(knit  = TRUE)

or perhaps as a separate step

gists('minepublic')[[1]] %>% knit() %>% edit()

DESCRIPTION file

It'd be nice to use devtools::install_github for installation which requires a DESCRIPTION.

Improve gist return

The gist class is extremely frustrating to work with. Unless I'm doing something wrong, the actual gist ids are inaccessible. e..g.

> x<- gists("minepublic")
> x[[1]]
<gist>44eb9788a675d42e6dd5
  URL: https://gist.github.com/44eb9788a675d42e6dd5
  Description: 
  Public: TRUE
  Created/Edited: 2015-02-16T09:11:54Z / 2015-02-16T09:11:54Z
  Files: temp.geojson

I would love to just have a simple data.frame (or list that can be easily flattened) to work with for a practical use case other than uploading. like

gist("minepublic") %>%
 filter(title = "temp") %>%
delete 

`tabl()` makes rows for each file in a gist

Can do 2 things with tabl()

  • Separate row for each file, or
  • concatenate fields where there are multiple unique values into one comma sep string

We basically do the first now, but then other fields aren't filled in for each row, and when combined with other gists, means the gist id rows belong with are lost.

I think option 2 might be cleaner, but not sure

gist_map piping?

@karthik sorry to keep asking questions, but it looks like the file name for this fxn is only needed to append to the url (that is, no local file manipulation needed in the fxn). Can we just get that from the output of gist_create()?, and if so, then the output of gist_create() can be piped to gist_map() as it's first argument? Or are you trying to support if someone wants to use a local file too?

fix error catching

Error status code come before header check, and maybe stop instead of warn

Implementation using Reference Classes

I am experimenting with an implementation of gistr using reference classes and was wondering if this API would be cleaner. You will find my preliminary implementation here.

The idea is to allow a workflow that resembles this

# set options github.username and github.password
# alternately pass username and password as arguments
gist = Gist()

# get
gist$get('public') # get public gists
gist$get('starred') # get starred gists
gist$get(user = 'hadley') # get gists of a user
gist$get("d5029341cfa9c2d02fa9") # get a gist by id

# add_files and post
gist$add_files(path = ".")
gist$post("My First Gist")

# make some edits to the files you added to the gist
# fill out the gist_id (can be automated)
gist_id = 
gist$update(id = gist_id)

# delete files
# specific files
gist$delete(gist_id, files = files_to_delete)

# delete complete gist
gist$delete

One big advantage I see to using reference classes here is that we can implement pretty sophisticated stuff taking advantage of the fact that ref classes keep track of state. Another advantage is that the API would mirror the official gist API very closely, making it easier to adapt to any changes.

I look forward to comments/suggestions on using this approach.

integrate with blockbuilder.org for post-processing

blockbuilder.org is a very nice online gist editor primarily built for d3.js bl.ocks, but it could easily be used as an online gist editor for anything. Would it be worthwhile to add a function to open a gist in blockbuilder?

Problem with Unicode on Windows

I am running into an issue with creating gists with unicode characters.

The characters are mangled when I try this code:

library(curl)
d3 <- "https://github.com/mbostock/d3/archive/v3.0.6.zip"
tmp <- tempfile()
curl::curl_download(d3, tmp, mode = "wb")
unzip(tmp)
unlink(tmp)

library(gistr)
gistr::gist_create(files = "d3-3.0.6/d3.js")

This might be a Windows issue because the same code works fine for @cpsievert .

> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gistr_0.1.0 curl_0.5   

loaded via a namespace (and not attached):
 [1] bitops_1.0-6    digest_0.6.8    evaluate_0.5.5  formatR_1.0    
 [5] httpuv_1.3.2    httr_0.6.1      jsonlite_0.9.14 knitr_1.9      
 [9] magrittr_1.5    R6_2.0.1        Rcpp_0.11.4     RCurl_1.95-4.5 
 [13] stringr_0.6.2   tools_3.1.3 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.