Skip to content
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

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

Closed
jennybc opened this issue Mar 18, 2015 · 10 comments
Closed
Milestone

Comments

@jennybc
Copy link
Member

jennybc commented Mar 18, 2015

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.

@sckott
Copy link
Contributor

sckott commented Mar 18, 2015

@jennybc Thanks for this. I'll take a look...

@sckott
Copy link
Contributor

sckott commented Mar 18, 2015

working on this, but also noticed issues with binary files (images) created during knit process - trying to get that solved too

@sckott sckott modified the milestone: v0.2 Mar 18, 2015
@sckott
Copy link
Contributor

sckott commented Mar 18, 2015

@jennybc would you normally generate the md from that file with rmarkdown package (using render())? or knitr

@jennybc
Copy link
Member Author

jennybc commented Mar 18, 2015

Honestly I would click the button in RStudio, in this context. So I think that means render().

@sckott
Copy link
Contributor

sckott commented Mar 18, 2015

@jennybc okay, reinstall from master, then try it again, e.g.,

file <- system.file("examples", "example1.R", package = "gistr")
cat(readLines(file), sep = "\n") # peek at file
gist_create(file, knit = TRUE)

@jennybc
Copy link
Member Author

jennybc commented Mar 19, 2015

Yes it works! But … I like this example even more because I always want the gist to have source and pretty thing.

gist_create(file, description = "my description", knit = TRUE, include_source = TRUE)

Thanks.

@jennybc jennybc closed this as completed Mar 19, 2015
@jennybc
Copy link
Member Author

jennybc commented Mar 19, 2015

I just realized how garbled up my original example was. Good work figuring out what I meant to post.

So it seems the YAML front matter is quite important. Omit it and the knitted output you get in the gist is the html. How often would anyone want that? IDK but food for thought ….. Control via an argument like output_format of render() and default to markdown? I don't need a reply.

@sckott
Copy link
Contributor

sckott commented Mar 19, 2015

@jennybc just to clarify, are you saying that sometimes users may not have the front matter, so we should default to markdown output, but allow user to control via a parameter?

@jennybc
Copy link
Member Author

jennybc commented Mar 19, 2015

Yes exactly. But maybe I am atypical? I basically always want markdown. In addition to or instead of HTML. Even more so for a gist than in other contexts.

@sckott
Copy link
Contributor

sckott commented Mar 19, 2015

Right, okay. I'll play around with that, #34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants