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.
Related
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...
Trying to use various tools in R that produce images using the webshot package. In all cases I get "PHANTOM ERROR" like the one described below:
MWE with trace below, followed by my system information:
> library(webshot)
> URL <- "http://rstudio.github.io/leaflet/"
> webshot(URL, delay = 0.5)
I'm `fs` modules
PHANTOM ERROR: TypeError: undefined is not a constructor (evaluating 'require('fs').pathJoin(phantom.casperPath, 'modules', 'clientutils.js')')
TRACE:
-> phantomjs://platform/casper.js: 1309 (in function injectClientUtils)
-> phantomjs://platform/casper.js: 713 (in function evaluate)
-> phantomjs://platform/casper.js: 1008 (in function getCurrentUrl)
-> phantomjs://platform/casper.js: 1590 (in function runStep)
-> phantomjs://platform/casper.js: 406 (in function checkStep)
Error in webshot(URL, delay = 0.5) : webshot.js returned failure value: 1
> traceback()
2: stop("webshot.js returned failure value: ", res)
1: webshot(URL, delay = 0.5)
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] webshot_0.5.2
loaded via a namespace (and not attached):
[1] ps_1.6.0 digest_0.6.28 R6_2.5.1 jsonlite_1.7.2
[5] magrittr_2.0.1 evaluate_0.14 rlang_0.4.11 renv_0.14.0
[9] callr_3.7.0 rmarkdown_2.11 tools_4.1.1 xfun_0.26
[13] yaml_2.2.1 fastmap_1.1.0 compiler_4.1.1 processx_3.5.2
[17] htmltools_0.5.2 knitr_1.35
> Sys.info()
sysname
"Darwin" release "20.6.0"
version
"Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64"
...
> system(paste(webshot:::find_phantom(), "--version"))
2.1.1
I tried:
restarting R
reinstalling phantomJS
installing an older version of phantomJS (not sure that took though)
updating xcode
updating xQuartz
reinstalling R
Nothing helped. All my colleagues can run this without error.
I'm trying to prepare an Rmarkdown file for a course. But for some reason (perhaps a very, very dumb reason) I can't seem to knit anything. Here is a very simple example of an Rmarkdown script:
---
title: "big data"
author: "CAM"
date: "21 March 2020"
output:
html_document: default
---
```{r,chunk1,eval=TRUE,echo=TRUE,include=TRUE}
seq(1,10,by=1)
```
This throws the error:
Error in parse(text = x, keep.source = TRUE) :
attempt to use zero-length variable name
Calls: <Anonymous> -> <Anonymous> -> getParseData -> parse
Execution halted
The code itself executes in the chunk, but it won't knit.
Here is my session info. (I just moved to catalina on mac, maybe there's a problem here).
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3
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.6/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
[6] methods base
other attached packages:
[1] knitr_1.28 rmarkdown_2.1
loaded via a namespace (and not attached):
[1] compiler_3.6.3 htmltools_0.4.0 tools_3.6.3
[4] yaml_2.2.1 Rcpp_1.0.3 xfun_0.12
[7] digest_0.6.25 rlang_0.4.5 evaluate_0.14
Found the answer. It's has to be saved as a .Rmd file, not an .R file. This is the case even if you selected your script as a Rmarkdown file within RStudio.
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.
I find myself confronted with a problem for which I fail to find a clue to a solution - which makes it very hard to actually deal with it.. Here goes: In R (with R-Studio) I try to create a Date object with the library lubridate:
library(lubridate)
ymd(20161001)
which results in an error:
Error in as.POSIXlt.POSIXct(x, tz) :
(converted from warning) unknown timezone 'GMT'
A second run (and any subsequent runs) of the last command yields the correct result:
ymd(20161001)
[1] "2016-01-01"
until I restart my R-session, when again the first run triggers an error. I've checked several settings, but can't find anything changing from the first to the second run. Here's, for instance, the output of my sessionInfo():
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.6.0
loaded via a namespace (and not attached):
[1] magrittr_1.5 tools_3.3.2 stringi_1.1.2 stringr_1.1.0
Sys.timezone() says [1] "Europe/Berlin", and Sys.getenv('TZ') is empty: ""
I do find others stumbling upon the same warning, such as this blogpost or here, but these problems have to do with times, whereas I would prefer to ignore times altogether, and deal with dates only.
I was getting the same error today. My code was in an Rmarkdown file set to output as a tufte_html document. I was loading the following packages:
library(lubridate)
library(tidyverse)
library(stringr)
library(extrafont)
library(extrafontdb)
library(tufte)
To get my code working I did the following:
First, I got off my company's VPN, suspecting that maybe it was the problem, but I was still getting the error when using my home wifi and no VPN. Next, I updated all my packages but was still getting the error.
Then, I shut down my Macbook and rebooted but was still getting the error.
Finally, I changed my script to no longer load tidyverse as a whole but instead load:
library(lubridate)
library(tibble)
library(dplyr)
library(readr)
library(extrafont)
library(extrafontdb)
library(tufte)
Then my Rmarkdown file rendered to html without the unknown timezone error. Unfortunately, I cannot pinpoint what exactly fixed the error or why loading parts but not the whole tidyverse seemed to do the trick for me. Did you ever solve your problem?
My session info when it worked:
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.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.4/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
other attached packages:
[1] tufte_0.2 extrafontdb_1.0 extrafont_0.17 stringr_1.2.0
[5] readr_1.1.1 dplyr_0.7.4 tibble_1.3.4 lubridate_1.7.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.13 Rttf2pt1_1.3.4 knitr_1.17 bindr_0.1
[5] magrittr_1.5 hms_0.3 R6_2.2.2 rlang_0.1.4
[9] tools_3.4.2 htmltools_0.3.6 yaml_2.1.14 rprojroot_1.2
[13] digest_0.6.12 assertthat_0.2.0 bindrcpp_0.2 glue_1.2.0
[17] evaluate_0.10.1 rmarkdown_1.8 stringi_1.1.6 compiler_3.4.2
[21] backports_1.1.1 pkgconfig_2.0.1
The answer to this question worked for me.
I added Sys.setenv(TZ='America/Detroit') to my script, for example.
The solution presented here R error: unknown timezone with as.POSIXct()
In my case, after including Sys.setenv(TZ="America/Lima") at the beginning of the code everything works fine.
Please check the list of valid TZ values at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones