rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 335 forks source link

Error when running serve_site(): "Error in as.vector(x, "character"): cannot coerce type 'environment' to vector of type 'character'" #365

Closed bagasbgy closed 5 years ago

bagasbgy commented 5 years ago

When running serve_site(), I get an error like this:

Error in as.vector(x, "character"): cannot coerce type 'environment' to vector of type 'character'

The problem is I can't get more information about the error from the message, so I can't track where I got wrong.

Previously, It is running well on my desktop. Just got this error after not blogging for a while.

If this is helping, this is my blog repo: https://github.com/bagasbgy/blog. And this is my sessionInfo():

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19.1

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

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

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

other attached packages:
[1] blogdown_0.10.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0        bookdown_0.9      digest_0.6.18     later_0.7.5.9001 
 [5] R6_2.3.0          magrittr_1.5      evaluate_0.12     rstudioapi_0.9.0 
 [9] promises_1.0.1    rmarkdown_1.11    tools_3.5.2       servr_0.11.2     
[13] httpuv_1.4.5.9002 xfun_0.4          compiler_3.5.2    htmltools_0.3.6  
[17] knitr_1.21
yihui commented 5 years ago

Here is the first step for debugging: make a copy of your website project (i.e. make a backup), delete all Rmd files (file.remove(list.files(, '[.]Rmd$', recursive = TRUE, full.names = TRUE))), and blogdown::serve_site(). If the error disappears, there must be something wrong in a certain Rmd, and blogdown is unlikely to be the culprit.

bagasbgy commented 5 years ago

Thanks @yihui for the suggestion, but already tried it, still, had no luck:

03:29:04 > file.remove(list.files(, '[.]Rmd$', recursive = TRUE, full.names = TRUE))
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
03:29:06 > blogdown::serve_site()
Building sites … WARN 2019/02/07 03:29:15 Data for key 'font_size_small' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'name' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'google_fonts' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'heading_font' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'body_font' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'nav_font' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'mono_font' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree
WARN 2019/02/07 03:29:15 Data for key 'font_size' in path 'hugo-academic/fonts/default.toml' is overridden by higher precedence data already in the data tree

                   | EN  
+------------------+----+
  Pages            | 41  
  Paginator pages  |  0  
  Non-page files   | 14  
  Static files     | 16  
  Processed images |  3  
  Aliases          | 15  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 1478 ms
Error in as.vector(x, "character") : 
  cannot coerce type 'environment' to vector of type 'character'

I'm sorry I forgot to tell you that build_site() run successfully--even with all of my .Rmds. I also tried to install devel version of servr, and still got the error.

So any suggestion to debug why serve_site() got that error?

yihui commented 5 years ago

Does traceback() tell you anything? Can you also try to use the CRAN versions of later and httpuv (remember to restart R)?

bagasbgy commented 5 years ago

Well, after installing the CRAN versions of later and httpuv, it works again!

This is the output from traceback() when it still got an error, maybe it could helps:

10:31:41 > traceback()
11: as.character.default(X[[i]], ...)
10: FUN(X[[i]], ...)
9: lapply(list(...), as.character)
8: .makeMessage(..., domain = domain, appendLF = appendLF)
7: message("To stop the server, run servr::daemon_stop(\"", server, 
       "\")", " or restart your R session")
6: daemon_hint(id)
5: res$start_server(app)
4: dynamic_site(dir, ..., build = watch_dir(watch, pattern = pattern, 
       all_files = all_files, handler = handler))
3: servr::httw(site.dir = pdir, baseurl = baseurl, handler = function(...) {
       files = c(...)
       files = files[substr(files, 1, n) != pdir]
       if (length(grep("(_?layouts?|static)/|[.](toml|yaml)$", files)) || 
           length(grep(md_pattern, files))) 
           build_site(TRUE)
   }, dir = ".", ...)
2: serve(...)
1: blogdown::serve_site()

Thank you so much @yihui !

yihui commented 5 years ago

That was very helpful. I just fixed the issue in servr. If you use the dev version of httpuv, you'll have to use the dev version of servr, too. Thanks!

mdozmorov commented 5 years ago

@yihui - got the same problem. Even after remotes::install_github('rstudio/blogdown') and (file.remove(list.files(, '[.R]md$', recursive = TRUE, full.names = TRUE))), blogdown::serve_site() gives:

Error in as.vector(x, "character") : 
  cannot coerce type 'environment' to vector of type 'character'

and the the output from traceback():

11: as.character.default(X[[i]], ...)
10: FUN(X[[i]], ...)
9: lapply(list(...), as.character)
8: .makeMessage(..., domain = domain, appendLF = appendLF)
7: message("To stop the server, run servr::daemon_stop(\"", server, 
       "\")", " or restart your R session")
6: daemon_hint(id)
5: res$start_server(app)
4: dynamic_site(dir, ..., build = watch_dir(watch, pattern = pattern, 
       all_files = all_files, handler = handler))
3: servr::httw(site.dir = pdir, baseurl = baseurl, handler = function(...) {
       files = c(...)
       files = files[substr(files, 1, n) != pdir]
       if (length(grep("(_?layouts?|static)/|[.](toml|yaml)$", files)) || 
           length(grep(md_pattern, files))) 
           build_site(TRUE)
   }, dir = ".", ...)
2: serve(...)
1: blogdown::serve_site()

The same website worked two month ago. Please, help.

yihui commented 5 years ago

@mdozmorov When in doubt, upgrade. And restart R. If the problem persists, please read the issue guide and provide the necessary information: https://github.com/rstudio/blogdown/blob/master/.github/ISSUE_TEMPLATE.md

mdozmorov commented 5 years ago

Thank you, @yihui, updating R and packages helped. This issue extending the list of solved ones at https://yihui.name/en/2017/05/when-in-doubt-upgrade/

yihui commented 5 years ago

@mdozmorov Perfect. Thanks for letting me know! :)