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

Error in knit2html when called from Rmd file on rstudio.cloud because default chunk options are missing #1571

Closed
skranz opened this issue Jul 6, 2018 · 3 comments
Milestone

Comments

@skranz
Copy link

@skranz skranz commented Jul 6, 2018

Dear Yihui,

I encountered a very strange bug when using knitr::knit2html on the rstudio.cloud. It took me quite some time to get to the core of the problem in a simple example. But here it is.

In the following rstudio.cloud project

https://rstudio.cloud/project/46324

There is the R file knitr_test.R with the following code:

library(knitr)
txt = "```{r 'test_chunk'}\n1+1\n```"
html = knitr::knit2html(text=txt,fragment.only = TRUE, quiet=TRUE)
html
# No error because default chunk options are there in the R file
knitr::opts_chunk$get()

The call to knit2html works perfectly fine there. The strange thing is that I have the same code in a chunk in the Rmd file knitr_test.Rmd. When I run the code there, knit2html stops with an error

Quitting from lines 2-3 () 
Error in Encoding(x) : a character vector argument expected

traceback() then shows

10: Encoding(x) 
9: native_encode(options$fig.path) 
8: fix_options(params) 
7: call_block(x)
6: process_group.block(group)
5: process_group(group)
4: withCallingHandlers(if (tangle) process_tangle(group) else process_group(group),         error = function(e) {            setwd(wd)            cat(res, sep = "\n", file = output %n% "")            message("Quitting from lines ", paste(current_lines(i),                 collapse = "-"), " (", knit_concord$get("infile"),                 ") ")        })
3: process_file(text, output)
2: knit(input, text = text, envir = envir, encoding = encoding,         quiet = quiet) 
1: knitr::knit2html(text = txt, fragment.only = TRUE, quiet = TRUE)

Further investigation with the debugger shows that options$fig.path is set to NULL. Inside the Rmd file I get the following chunk options:

> knitr::opts_chunk$get()
$error
[1] FALSE

Yet running the same line in the R file, I get, a lot of default options:

> knitr::opts_chunk$get()
$eval
[1] TRUE

$echo
[1] TRUE

$results
[1] "markup"

$tidy
[1] FALSE

$tidy.opts
NULL

$collapse
[1] FALSE

$prompt
[1] FALSE

$comment
[1] "##"

$highlight
[1] TRUE

$strip.white
[1] TRUE

$size
[1] "normalsize"

$background
[1] "#F7F7F7"

$cache
[1] FALSE

$cache.path
[1] "cache/"

$cache.vars
NULL

$cache.lazy
[1] TRUE

$dependson
NULL

$autodep
[1] FALSE

$cache.rebuild
[1] FALSE

$fig.keep
[1] "high"

$fig.show
[1] "asis"

$fig.align
[1] "default"

$fig.path
[1] "figure/"

... AND SO ON ...

So for some strange reason default options don't seem to be set if knit2html
is called from an Rmd file on rstudio.cloud.
On my local windows desktop I don't have the problem.
All default options are also set when called from an .Rmd chunk.

If you don't know how to fix it (or it is a difficult shiny cloud issue),
do you perhaps know a simple workaround to set the default knitr options manually?

Best wishes,
Sebastian

@skranz
Copy link
Author

@skranz skranz commented Jul 6, 2018

BTW: Since I am not sure whether that is more of a knitr or rstudio.cloud issue, I referenced this issue on the rstudio cloud discussion forum:

https://community.rstudio.com/t/cant-correctly-call-knit2html-in-rstudio-cloud-by-pasting-code-from-an-rmd-file

@yihui
Copy link
Owner

@yihui yihui commented Jul 6, 2018

I don't have access to your RStudio Cloud project.

Let's keep the discussion in the RStudio Community before we can confirm this is really a knitr bug. Thanks!

@yihui yihui closed this as completed Jul 6, 2018
@yihui yihui added this to the v1.21 milestone Jul 6, 2018
@github-actions
Copy link

@github-actions github-actions bot commented Nov 10, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants