rstudio / blogdown

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

blogdown find_config() cannot find config.yaml file in working directory #661

Closed zdebruine closed 3 years ago

zdebruine commented 3 years ago

Note: Duplicate of this StackO post.

I have a blogdown site built with Hugo that I last successfully served with blogdown two days ago. Yesterday, when I tried to build a post again (without having changed anything else in the meantime) I got shot this error:

> blogdown::build_site()
Error in find_config() : 
  Cannot find the configuration file config.toml | config.yaml of the website

Well, here is the result of list.files() in my working directory:

> cat(list.files())
assets config config.yaml content layouts netlify.toml resources static themes mydomain.com.Rproj

Note the conspicuous presence of config.yaml.

Note that this issue is not isolated to blogdown::build_site() -- any Rstudio add-in function provided by blogdown returns the same issue.

Here is my SessionInfo():

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
[1] blogdown_1.5

loaded via a namespace (and not attached):
 [1] compiler_4.0.3  bookdown_0.24   fastmap_1.1.0   htmltools_0.5.2 tools_4.0.3     yaml_2.2.1      rmarkdown_2.11  knitr_1.36     
 [9] xfun_0.26       digest_0.6.27   rlang_0.4.11    evaluate_0.14  

If it's worth anything, here's a link to my blog source files: https://github.com/zdebruine/zachdebruine.com In fact, if you download the .zip, unzip it, and open up the Rstudio project, you'll get the same error from blogdown on attach.

yihui commented 3 years ago

I can't reproduce your problem:

> blogdown::build_site()
Start building sites … 
hugo v0.88.1+extended darwin/amd64 BuildDate=unknown

                   | EN  
-------------------+-----
  Pages            | 51  
  Paginator pages  |  0  
  Non-page files   | 47  
  Static files     | 17  
  Processed images | 34  
  Aliases          | 16  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 536 ms

Do you have anything suspicious in your global ~/.Rprofile? And what does blogdown:::site_root() return?

zdebruine commented 3 years ago

Thanks for the help @yihui!

blogdown:::site_root() is returning one level lower than the directory of the blog (i.e. C:/Users/Owner/Desktop) instead of C:/Users/Owner/Desktop/blogdownsite.com).

So I tried adding options(blogdown.site_root = "C:/Users/Owner/Desktop/blogdownsite.com") to my ~/.Rprofile file, but after restarting R that didn't change the output of blogdown:::site_root() or fix the issue with not finding config.yaml.

This is my ~/.Rprofile file:

if (file.exists("~/.Rprofile")) {
  base::sys.source("~/.Rprofile", envir = environment())
}
options(
  blogdown.serve_site.startup = FALSE,
  blogdown.knit.on_save = TRUE,
  blogdown.method = 'html'
)
options(blogdown.hugo.version = "0.88.1")

Thanks again for the help!

yihui commented 3 years ago

I mean ~/.Rprofile (i.e., the one under your home directory), not the .Rprofile in your project (I can see the latter in your repo).

xfun::file_string('~/.Rprofile')
zdebruine commented 3 years ago

Here is my Rprofile.site file contents:

options(help_type="html")
zdebruine commented 3 years ago

blogdown:::site_root() is returning one level lower than the directory of the blog (i.e. C:/Users/Owner/Desktop) instead of C:/Users/Owner/Desktop/blogdownsite.com).

I moved config.yaml to the current blogdown:::site_root() which is C:/Users/Owner/Desktop and now the site builds. But I would like to change the site_root() to C:/Users/Owner/Desktop/blogdownsite.com, however this hasn't worked using options(blogdown.site_root = "C:/Users/Owner/Desktop/blogdownsite.com"). How else do I do this?

Related: https://community.rstudio.com/t/blogdown-serve-site-from-subdirectory/94658

yihui commented 3 years ago

That's really weird. I can't think of a reason why find_config() couldn't find config.yaml, and have to ask a few extra questions:

  1. How did you open the project? I assume that you opened zachdebruine.com.Rproj.

  2. What's your working directory? i.e., getwd(). I expect it to be C:/Users/Owner/Desktop/blogdownsite.com if you did what I assumed in the first question.

  3. How did you create this site? If you created it using the RStudio wizard or blogdown::new_site(), you must have an index.Rmd in the root dir like this: https://github.com/rbind/yihui/blob/master/index.Rmd But it should be fine if it doesn't exist.

Before we figure out why, I don't recommend that you try options(blogdown.site_root). It should be rare for general users to have to set this option.

zdebruine commented 3 years ago
  1. yes, I opened zachdebruine.com.Rproj
  2. yes, getwd() is C:/Users/Owner/Desktop/blogdownsite.com.
  3. I used blogdown::new_site(). index.md exists in the /content directory, I think that's due to the wowchemy theme?

It always worked as expected, but I must have changed something in the last two days. I could try starting over with the site and copying the posts across, but I'm not eager to do that.

I don't get why the root directory is one level higher than the site directory. It shouldn't be. Where is the root directory set?

zdebruine commented 3 years ago

I think I've got it. I started a new blogdown site, copied over all files except config.yaml, added in just the theme and modules to the new config.yaml file from the old one, and now the site is building as normal. Something else in config.yaml must have been causing the trouble, and I haven't yet figured out what it was.

Sorry for the bother, but I'm happy to be back up and running.

yihui commented 3 years ago

Okay, I'm glad that the problem is gone, although we don't know what happened :)