pkgdown icon indicating copy to clipboard operation
pkgdown copied to clipboard

Empty README.md file in package root directory causes error

Open jonnybaik opened this issue 2 years ago • 1 comments

I initialized a package with an empty README.md intending to fill it in later, and when I later tried to build a site with pkgdown::build_site(), I ran into an error:

> # Build pkgdown documentation site
> build_site(pkg = "/path/to/R/package")

-- Installing package into temporary library -----------------------------------
ℹ Using R 4.2.3 (lockfile was generated with R 4.1.3)
== Building pkgdown site =======================================================
Reading from: '/path/to/R/package'
Writing to:   '/path/to/R/package/docs'
-- Initialising site -----------------------------------------------------------
-- Building home ---------------------------------------------------------------
Error: 
! in callr subprocess.
Caused by error in `UseMethod("xml_find_first")`:
! no applicable method for 'xml_find_first' applied to an object of class "NULL"
ℹ See `$stdout` for standard output.
Type .Last.error to see the more details.


> .Last.error

<callr_error/rlib_error_3_0/rlib_error/error>
Error: 
! in callr subprocess.
Caused by error in `UseMethod("xml_find_first")`:
! no applicable method for 'xml_find_first' applied to an object of class "NULL"
ℹ See `$stdout` for standard output.
---
Backtrace:
1. pkgdown::build_site(pkg = "/path/to/R/package")
2. pkgdown:::build_site_external(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
3. callr::r(function(..., cli_colors, pkgdown_internet) { …
4. callr:::get_result(output = out, options)
5. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))
---
Subprocess backtrace:
 1. pkgdown::build_site(...)
 2. pkgdown:::build_site_local(pkg = pkg, examples = examples, run_dont_run = run_dont_run, …
 3. pkgdown::build_home(pkg, override = override, preview = FALSE)
 4. pkgdown::build_home_index(pkg, quiet = quiet)
 5. pkgdown:::markdown_body(src_path)
 6. xml %>% xml2::xml_find_first(".//body") %>% xml2::write_html(transformed_path, …
 7. xml2::write_html(., transformed_path, format = FALSE)
 8. xml2::xml_find_first(., ".//body")
 9. base::.handleSimpleError(function (e) …
10. global h(simpleError(msg, call))

The error wasn't very informative, but I was able to fix the issue by removing the README.md file in the package root directory.

Following the error trace, the build_home_index() function seems to check if specific files exist (e.g. "pkgdown/index.md", "index.md", "README.md"), but if those files exist and are empty, it results in an error.

jonnybaik avatar May 19 '23 18:05 jonnybaik

Oh, interesting edge case, maybe pkgdown should indeed first check the file is not empty. :thinking:

Another way to create a README.md to fill in later would be to run usethis::use_readme_md(), with which you get a boilerplate README.

maelle avatar May 25 '23 10:05 maelle