Error creating notebook: no lines available in input - r

When trying to Preview a simple notebook in RStudio, I am getting the following error in the top of the source pane and no nb.html file is created:
"Error creating notebook: no lines available in input"
Screenshot:
> sessionInfo(package = NULL)
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252 LC_NUMERIC=C LC_TIME=German_Austria.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.6 tools_3.3.3 base64enc_0.1-3 yaml_2.1.14 Rcpp_0.12.12 stringi_1.1.3 rmarkdown_1.8 knitr_1.17
[12] stringr_1.2.0 digest_0.6.12 evaluate_0.10
> RStudio.Version()
$mode
[1] "desktop"
$version
[1] ‘1.0.153’

I wasn't able to replicate the exact error but you could try writing the output html notebook in same line.
---
title: "R Notebook"
output: html_notebook: default
html_document: default
---

I fixed this by opening a new Notebook, copying the contents of my original, error-ing Notebook there, and then overwriting the original Notebook. The error presented, for me, after I moved a folder containing all the files associated with this project to a new location.

Related

Quarto Not Rendering

My quarto documents have stopped rendering suddenly. I have reinstalled RStudio and the quarto package, but this issue persists.
When I open a new quarto document, I no longer see the boilerplate material in the new document. The document is empty as if I had selected Create Empty Document, but I haven't.
Then, the document renders when all I include is raw text, but when I include an r code chunk, I get the following message.
Error in xfun::normalize_path(path, ..., must_work = must_work, resolve_symlink = FALSE) :
unused argument (resolve_symlink = FALSE)
Calls: .main ... execute -> setwd -> dirname -> <Anonymous> -> normalize_path
Execution halted
Here is the quarto document I'm attempting to render.
---
title: "Testing"
---
```{r}
mtcars |> print()
```
Here is my session info:
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 ps_1.7.2 digest_0.6.30 later_1.3.0
[5] jsonlite_1.8.4 pacman_0.5.1 evaluate_0.20 zip_2.2.2
[9] rlang_1.0.6 cli_3.4.1 rstudioapi_0.14 fs_1.5.2
[13] rmarkdown_2.20 tools_4.2.2 yaml_2.3.6 xfun_0.35
[17] fastmap_1.1.0 parallel_4.2.2 compiler_4.2.2 processx_3.8.0
[21] htmltools_0.5.4 knitr_1.41 quarto_1.2
I was having the exact same issue with knitr, this worked for me:
Remove the package "xfun" from the packages section, then reinstall it immediately after.
I'd tried changing the root install for R and everything. Turns out it was just xfun being weird.
Found the solution on the Posit Community forum.
Do you have any spaces in the filename or file path? That was preventing me from rendering for a bit.

R Markdown stops rendering when encountering a chunk with base R graphics

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.3
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.1 fastmap_1.1.0 cli_3.3.0 htmltools_0.5.3 tools_4.2.1 yaml_2.3.5
[7] rmarkdown_2.14 gdata_2.18.0.1 knitr_1.39 xfun_0.31 digest_0.6.29 rlang_1.0.2
[13] gtools_3.9.3 evaluate_0.15
I have an issue where RMarkdowns stop knitting (without error) when encountering chunks with graphics/plots.
I experience this issue even with the default RMarkdown with summary(cars) and plot(pressure). However, when I comment out the plot(pressure) chunk, the .html file is rendered successfully and I get an output instantaneously.
I was getting the following error as well:
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
and I tried remotes::install_version("rlang", "1.0.2") as suggested here:
https://github.com/rstudio/rstudio/issues/11552
But that hasn't solved this issue.
Any help or tips appreciated...

Cross-referencing of sections in bookdown::word_document2 not working [duplicate]

This question already has answers here:
Bookdown: Chapter/Section cross referencing not working (gitbook)
(2 answers)
Closed 3 years ago.
Title says it all. See below for a minimal (non-)working example.
---
title: "Untitled"
author: "Anonymous"
date: "09/01/2020"
output: bookdown::word_document2
---
# First Section {#sec1}
Etc.
# Second Section
See section \#ref(sec1).
When I knit the above, I get the following warning:
Output created: mre.docx
Warning message:
The label(s) sec1 not found
The reference in the output is replaced with two question marks (??). When I replace the output option in the YAML header with pdf_document2, there is no error. My template.docx has section numbering enabled for all heading styles and the sections are numbered correctly (just not the references).
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux
Matrix products: default
BLAS: /usr/lib/libblas.so.3.9.0
LAPACK: /usr/lib/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 Matrix_1.2-18 bookdown_0.16 htmltools_0.4.0 tools_3.6.2 yaml_2.2.0 reticulate_1.13 Rcpp_1.0.3 rmarkdown_1.17 grid_3.6.2 knitr_1.26 jsonlite_1.6
[13] digest_0.6.22 xfun_0.11 rlang_0.4.1 lattice_0.20-38 evaluate_0.14
> pandoc --version
pandoc 2.8
Compiled with pandoc-types 1.20, texmath 0.12, skylighting 0.8.3
I have been struggling with the same issue and I found a workaround
This is a known issue that the Rstudio group is working on.
https://github.com/rstudio/bookdown/issues/787
I was able to work around this problem by using the version of pandoc that is installed with Rstudio (currently 2.7.2). In windows I did this by removing pandoc from the PATH and then restarting my Rstudio session.

Bookdown not building - replacement length zero

I'm getting the following error when trying to build this gitbook on my local machine (was trying to use it as a template for creating my own work):
https://github.com/lgatto/IntroMachineLearningWithR
Error:
Error in x[i] <- sprintf("<a href=\"%s#%s\"", filenames[which.max(lines[lines <= :
replacement has length zero
Calls: <Anonymous> ... <Anonymous> -> split_chapters -> restore_links -> lapply -> FUN
Also the warning below comes up, but this is probably less mission critical to fix:
In addition: Warning message:
In split_chapters(output, gitbook_page, number_sections, split_by, :
You have 6 Rmd input file(s) but only 5 first-level heading(s). Did you forget first-level headings in certain Rmd files?
Session info:
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.1 backports_1.1.2 bookdown_0.7 rsconnect_0.8.8 rprojroot_1.3-2 htmltools_0.3.6
[7] tools_3.5.1 yaml_2.2.0 Rcpp_0.12.19 rmarkdown_1.10 knitr_1.20 xfun_0.4
[13] digest_0.6.18 evaluate_0.12
I'm very late to the game on this one, but make sure the first-level heading in the .rmd file you're knitting is #, and not ## or ### and so on. I was having the same error, and this resolved it for me.

Images not showing in R notenook (nb.html file)

When I knit to HTML, images show up fine in the .html file, but not the .nb.html one. MWE is the R Notebook template: the plot(cars) image does not show.
Per suggestions listed here: RStudio notebook does not show data.frames when I compile, I tried older/newer/dev versions of rmarkdown. I also tried newer/dev versions of knitr. Nothing helped. I have RStudio version 1.0.136.
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X Yosemite 10.10.5
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.12.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 withr_1.0.2 digest_0.6.11 rprojroot_1.2 R6_2.2.0
[6] jsonlite_1.2 backports_1.0.5 git2r_0.15.0 magrittr_1.5 evaluate_0.10
[11] highr_0.6 httr_1.2.1 stringi_1.1.2 curl_2.3 rstudioapi_0.6
[16] rmarkdown_1.3 tools_3.3.2 stringr_1.1.0 yaml_2.1.14 rsconnect_0.7
[21] base64enc_0.1-3 memoise_1.0.0 htmltools_0.3.5 knitr_1.15.8
Thanks to RStudio for pointing out that this is expected behavior. I had switched the chunk output setting to Chunk Output in Console so I could view plots in the plot window. I didn't realize that all chunks must be run inline to appear in the notebook. I switched back to Chunk Output Inline, ran the chunks, and all was well.

Resources