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 when running serve_site(): "Error in as.vector(x, "character"): cannot coerce type 'environment' to vector of type 'character'" #365

Closed
bagasbgy opened this issue Feb 6, 2019 · 9 comments
Milestone

Comments

@bagasbgy
Copy link

bagasbgy commented Feb 6, 2019

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
Copy link
Member

yihui commented Feb 6, 2019

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
Copy link
Author

bagasbgy commented Feb 6, 2019

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
Copy link
Member

yihui commented Feb 6, 2019

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

@bagasbgy
Copy link
Author

bagasbgy commented Feb 7, 2019

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
Copy link
Member

yihui commented Feb 7, 2019

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!

@yihui yihui added this to the v0.11 milestone Feb 7, 2019
@mdozmorov
Copy link

@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
Copy link
Member

yihui commented Mar 19, 2019

@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
Copy link

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
Copy link
Member

yihui commented Mar 20, 2019

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

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

3 participants