`blogdown:::new_post_addin()` returning `Error in parser(f) : could not find function "parser"`

Hey y'all, I'm having a weird error that I can't find reported anywhere, which always makes me nervous that I'm doing something stupid. Or maybe I have my box in a weird unexpected state.

So after 2 years of no blog posts I decided it was time to make a new blog post. I dusted off my GitHub repo and fired up R because my blog is in RMarkdown using the blogdown package. I immediately tried to use the addins and the New Post option to make a new post. I was met with:

Error in parser(f) : could not find function "parser"

Uhh... ok. So I validated that my version of R was up to date (4.2.2) and then I checked RStudio... it's at 2022.07.2. Then I updated all packages using the Packages menu in RStudio. Then I manually forced blogdown to install, just to be sure.

yet still when I run the underlying command from that Addin, I get the same response:

> blogdown:::new_post_addin()
Error in parser(f) : could not find function "parser"

So I went on a hunt to find where this is coming from. Here's my best guess:

blogdown:::new_post_addin()

calls:
blogdown:::archetypes()

which calls:
blogdown:::module_paths()

which calls
blogdown:::read_config()

which can be found here, but is:

read_config = function(f) {
  parser = switch(
    basename(f), 'config.toml' = read_toml, 'config.yaml' = yaml_load_file
  )
  parser(f)
}

and that call fails with
Error in parser(f) : could not find function "parser"

but it makes zero sense to me that I would be the only person on the planet having this issue. Any clue what's going on?

update:

the plot thickens... I thought, "JD, (that's what I call me) why don't you just use RStudio Cloud and do your blog post there! You've clearly borked something on your local stack so start fresh with a Cloud instance!" So I went to the newly rebranded posit.cloud and started a new workspace. Then I cloned my GitHub repo then I opened the project file inside of the repo. I had weird trouble with it not wanting to change the working directory to the new directory because I already had a working directory, so I over-rode that with setwd('/cloud/project/CerebralMastication-hugo')

and I ended up with:

> setwd('/cloud/project/CerebralMastication-hugo')
> getwd()
[1] "/cloud/project/CerebralMastication-hugo"
> blogdown:::new_post_addin()
Error in parser(f) : could not find function "parser"

which is the same parser/switch problem. My repo has a config.toml in there:

image

So now I'm even more confused... this must be something about my specific blog project.

Have you run blogdown::check_site() to make sure your blog/theme config is compatible with the latest blogdown version?

I never use the addin because it doesn't play well with my theme, it works but it messes with the multilingual content structure of my particular theme. Maybe the addin is not compatible with your theme either?

Hi @jdlong !

Can you share your Posit Cloud space ? Or just the repo I should clone ?

It seems there could be an issue where f is not the correct file somehow...

Also, I think you can open an issue in blogdown so that we at least error better on this. I think we do not expect that none of the file would be found. We should error if parser is NULL obviously.

Thank you

I didn't know about check_site()! so I ran it. And here's the output:

> blogdown::check_site() 
โ€• Running a series of automated checks for your blogdown website project...
------------------------------------------------------------------------------------------------------------------------------------------------------
โ—‹ A successful check looks like this.
โ— [TODO] A check that needs your attention looks like this.
| Let's check out your blogdown site!
------------------------------------------------------------------------------------------------------------------------------------------------------
โ€• Checking config.toml
| Checking "baseURL" setting for Hugo...
โ—‹ Found baseURL = "https://cerebralmastication.com/"; nothing to do here!
| Checking "ignoreFiles" setting for Hugo...
โ— [TODO] Set "ignoreFiles" to ["\\.Rmd$", "\\.Rmarkdown$", "_cache$"]
| Checking setting for Hugo's Markdown renderer...
| You are using the Markdown renderer 'goldmark'.
โ— [TODO] Allow goldmark to render raw HTML by adding this setting to config.toml (see https://github.com/rstudio/blogdown/issues/447 for more info):

[markup]
  [markup.goldmark]
    [markup.goldmark.renderer]
      unsafe = true

โ–บ Do you want blogdown to set this for you? (y/n) y
โ€• Check complete: config.toml

โ€• Checking index.Rmd in the root directory
โ—‹ index.Rmd is correctly configured.
โ€• Check complete: index.Rmd

โ€• Checking .gitignore
| Checking for items to remove...
โ—‹ Nothing to see here - found no items to remove.
| Checking for items to change...
โ—‹ Nothing to see here - found no items to change.
| Checking for items you can safely ignore...
โ— [TODO] You can safely add to .gitignore: .DS_Store, Thumbs.db, .hugo_build.lock
| Checking for files required by blogdown but not committed...
โ—‹ Great! Did not find such files.
โ€• Check complete: .gitignore

โ€• Checking Hugo
| Checking Hugo version...
โ—‹ Found Hugo. You are using Hugo 0.107.0.
| Checking .Rprofile for Hugo version used by blogdown...
โ—‹ blogdown is using Hugo 0.107.0 to build site locally.
โ€• Check complete: Hugo

โ€• Checking netlify.toml...
โ— [TODO] netlify.toml was not found. Use blogdown::config_netlify() to create file.
โ€• Checking content files
| Checking for validity of YAML metadata in posts...
โ—‹ All YAML metadata appears to be syntactically valid.
| Checking for previewed content that will not be published...
โ—‹ Found 0 files with future publish dates.
โ—‹ Found 0 files marked as drafts.
| Checking your R Markdown content...
โ—‹ All R Markdown files have been knitted.
โ— [TODO] Found 1 R Markdown file to update by re-rendering:

  content/post/2020-07-27-using-python-sympy-in-a-python-code-chunk-in-rmarkdown.Rmd

  To update a file, re-knit or use blogdown::build_site(build_rmd = 'timestamp')
| Checking for .html/.md files to clean up...
โ—‹ Found 0 duplicate .html output files.
โ— [TODO] Found 1 incompatible .html file in the content directory:

  file.remove(c(
  "content/post/2020-07-27-using-python-sympy-in-a-python-code-chunk-in-rmarkdown.html"
  ))

  To fix, run the above command and then blogdown::build_site(build_rmd = "newfile").
| Checking for the unnecessary 'content/' directory in theme...
โ—‹ Great! Your theme does not contain the content/ directory.
โ€• Check complete: Content

Nothing really substantive appears... Addin New Post still doesn't work :frowning:

hey @cderv ! the repo is public so you can just clone it:

I have it loaded in Posit Cloud at Posit Cloud

thank you so much for the help! Later today I'll raise an issue on blogdown GitHub

issue raised: issue with odd error when `blogdown failed to find config file` ยท Issue #742 ยท rstudio/blogdown ยท GitHub

1 Like

I can't access the space it seems. But I'll be able to look at the repo.

1 Like

yes that works better if I set access to "everyone" prior to sharing the link

fixed now :slight_smile:

I just fixed the problem in blogdown: For error `could not find function "parser"`: fail more gracefully ยท Issue #742 ยท rstudio/blogdown ยท GitHub

You are probably the only person on the planet :slight_smile: The problem was caused by the file config.toml.bak.toml in your project, which triggered a bug in blogdown. Thanks for reporting it! I really appreciate it.

1 Like

My life exists to serve as an example to others.

Thank you @yihui for helping me track down this mystery!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.