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 in .rs.parsePackageDependencies(contents, extension) : object 'partition_yaml_front_matter' not found after update to R 4.2.1 #11552

Closed
4 tasks done
FMKerckhof opened this issue Jul 5, 2022 · 21 comments
Assignees
Labels
backport Issues whose associated fixes will need to be backported for a previous release. bug projects

Comments

@FMKerckhof
Copy link

@FMKerckhof FMKerckhof commented Jul 5, 2022

System details

RStudio Edition : Desktop 
RStudio Version :  2022.02.3 Build 492
OS Version      :  Windows 10 Enterprise 21H2 19044.1766
R Version       :  4.2.1 for windows 

Steps to reproduce the problem

  • Update a system with an existing project with R markdown with yaml frontmatter from R 4.2.0 to R 4.2.1
  • Update all packages using update.packages(ask = FALSE, checkBuilt = TRUE)
  • Observe error when starting the Rstudio IDE (most likely the error messages is displayed more than once)
  • Deleting .Rproj.user with the IDE closed and restarting removes the error message

Describe the problem in detail

This issue is referred to from an issue at rstudio/rmarkdown: rstudio/rmarkdown#2389

the error messages:

Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
  • Deleting .Rproj.user (or for some users a downgrade of rlang - cf. linked issue above) appears to resolve the problem - so something there (a certain cache?) appears to cause the error.

  • Creating a new project after the update also does not lead to the error message.

Describe the behavior you expected

  • Having to delete .Rproj.user is not something I would normally do when updating a minor version of R (or a major version for that matter)
  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
@ronblum
Copy link
Contributor

@ronblum ronblum commented Jul 5, 2022

@FMKerckhof Thanks for bringing over the issue! can you provide a simple example of an R Markdown file that causes this, specifically so that I can try to start with the same first step? This way I can try to reproduce exactly the same way.

Triage: Detailed conversation with @Cdrev is at the referenced rmarkdown issue.

@FMKerckhof
Copy link
Author

@FMKerckhof FMKerckhof commented Jul 5, 2022

Hi @ronblum I am not sure if the issue is linked to the markdown file in specific but rather to the way the project "caches" certain information in .Rproj.user. Since I thought - based upon the error message - that there was an issue in the frontmatter I have included a front matter as close to mine as possible. I am using custom css as well which I source from an internal package and that I cannot share here. However, it is loaded in the same way as the logo with a system.file call. I have here replaced the logo with an included image from magick - it will require that you have magick installed on windows to be able to run.

---
title: |
  ![](`r system.file("images", "building.jpg", package = "magick")`){width=25%}  
  Reprex for R markdown
author: "FM Kerckhof"
date: "`r Sys.Date()`"
fontsize: 9pt
output:
  html_document:
    code_folding: show
    highlight: haddock
    keep_md: yes
    theme: flatly
    toc: yes
    number_sections: true
    toc_float:
      collapsed: no
      smooth_scroll: yes
      toc_depth: 4
editor_options:
  chunk_output_type: console
---

# obviously the chunks below should have the triple apostrophes, but that messes with the github formatting 
``{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options("yaml.eval.expr" = TRUE)
``

## R Markdown

This is an R Markdown document. 

``{r cars}
summary(cars)
``

## Including Plots

You can also embed plots, for example:

``{r pressure, echo=FALSE}
plot(pressure)
``

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 5, 2022

What version of the rmarkdown package is installed?

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 5, 2022

This is where we call into rmarkdown:::partition_yaml_front_matter:

# extract the front matter from the document; accepts a list of lines and returns a list with
# $front_matter and $body elements
partitions <- rmarkdown:::partition_yaml_front_matter(
strsplit(x = contents, split = "\n", fixed = TRUE)[[1]])

The only way I can see this error occurring is if an unexpected version of rmarkdown were installed... but that function has existed for 9 years now (!) so it almost surely is not the culprit.

https://github.com/rstudio/rmarkdown/blame/main/R/output_format.R#L726

You could check whether rmarkdown:::partition_yaml_front_matter does indeed resolve to a valid function definition. Unfortunately without a reproducible example there's not much we can do.

@FMKerckhof
Copy link
Author

@FMKerckhof FMKerckhof commented Jul 5, 2022

@kevinushey apologies - it's pretty difficult to generate a reproducible example that includes switching R versions. I'll see if I can spin up some rocker/rstudio containers for each version and if I can reproduce the issue by upgrading the 4.2.0 to 4.2.1 container (although those are linux containers afaik). The rmarkdown package version is 2.14 both before and after the update. Checking my output of sessioninfo::package_info("rmarkdown") I can see at the time of the issue that the source was CRAN R 4.2.0 and after manual re-install the source is CRAN R 4.2.1. From what I understand this shouldn't be an issue though - the checkBuilt option of update.packages will not be triggered by that. Only when I deleted the .Rproj.user folder the error disappeared. Is there some sort of log/diagnostic that I can look into to see if I can further pinpoint the issue?

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 5, 2022

You could do something like the following:

options(rstudio.errors.suppressed = FALSE)
options(error = recover)

and then see if you can get the R debugger to "catch" the error, and introspect a bit more on the call stack / state of the rmarkdown package / other poking at the problem.

@daxiagithub
Copy link

@daxiagithub daxiagithub commented Jul 6, 2022

I have encountered the same issue. My R version is R 4.2.0. Besides the annoying error messages I saw when I open Rstudio, it didn't stop me running the code (however I couldn't render .Rmd file anymore), so I didn't bother to investigate further. I vaguely remember it happened after I upgraded Rstudio (or updated some R packages. Forgot which ones, sorry). Here is the printout of the error messages:

R version 4.2.0 (2022-04-22 ucrt) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found
> 
> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

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

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3     rstudioapi_0.13  knitr_1.39       magrittr_2.0.3   tidyselect_1.1.2 lattice_0.20-45  xtable_1.8-4     R6_2.5.1         rlang_1.0.3      fastmap_1.1.0    fansi_1.0.3     
[12] plyr_1.8.7       dplyr_1.0.9      tools_4.2.0      grid_4.2.0       nlme_3.1-157     xfun_0.31        utf8_1.2.2       DBI_1.1.3        cli_3.3.0        htmltools_0.5.2  emmeans_1.7.5   
[23] ellipsis_0.3.2   assertthat_0.2.1 yaml_2.3.5       digest_0.6.29    tibble_3.1.7     lifecycle_1.0.1  crayon_1.5.1     purrr_0.3.4      vctrs_0.4.1      glue_1.6.2       evaluate_0.15   
[34] rmarkdown_2.14   estimability_1.3 compiler_4.2.0   pillar_1.7.0     generics_0.1.2   lsmeans_2.30-0   mvtnorm_1.1-3    pkgconfig_2.0.3 
> 

My current Rstudio version is RStudio 2022.07.0+547 - Windows 10/11 (64-bit), but this happened at least a couple of versions back.

BTW, somebody else also reported the same problem here:
https://stackoverflow.com/questions/72802410/why-there-is-an-error-when-i-restart-my-rstudio-after-updating-rmarkdown-package

Thanks!

@kjewell
Copy link

@kjewell kjewell commented Jul 7, 2022

I have also been running into this over last few weeks, probably after the 4.2.1 install but maybe after an rstudio update? (running 2022.02.3 Build 492 on macos 12.4.)

My insight is that the error appears on startup (and only on startup) if a markdown document is in the selected tab of the Rstudio file editor. The error is delayed a second or two after the initial R startup text. If an R script is selected in the file editor, the error does not appear.

`R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found
Error in .rs.parsePackageDependencies(contents, extension) :
object 'partition_yaml_front_matter' not found

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] digest_0.6.29 R6_2.5.1 evaluate_0.15 httr_1.4.3 rlang_1.0.3 cli_3.3.0
[7] data.table_1.14.2 rstudioapi_0.13 rmarkdown_2.14 tools_4.2.1 xfun_0.31 fastmap_1.1.0
[13] yaml_2.3.5 compiler_4.2.1 htmltools_0.5.2 knitr_1.39 `

@daxiagithub
Copy link

@daxiagithub daxiagithub commented Jul 7, 2022

I second these observations. I also noticed that if you're running a r markdown notebook, it can't generate the .nb.html anymore.

My insight is that the error appears on startup (and only on startup) if a markdown document is in the selected tab of the Rstudio file editor. The error is delayed a second or two after the initial R startup text. If an R script is selected in the file editor, the error does not appear.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 7, 2022

Thanks, I was finally able to reproduce. In sum, I needed to do the following:

  1. Create a new RStudio project,
  2. Create an R Markdown document and save it,
  3. Create an R Notebook and save it,
  4. Re-open the project.

For me, the error only seems to occur if I have two documents open in the session.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 7, 2022

I think I've figured out the issue. The problem here is occurring in this way:

  1. RStudio calls .rs.parsePackageDependencies() to get package dependencies for the R Markdown document,
  2. The rmarkdown package is loaded, so that we can parse dependencies using some of the rmarkdown utility functions,
  3. Since rmarkdown depends on rlang, that package is loaded as well,
  4. rlang calls cli::builtin_theme() to figure out some theme details,
  5. cli::builtin_theme() tries to query information about the current theme with rstudioapi::getThemeInfo(),
  6. Evidently, that leads RStudio to calling back into .rs.parsePackageDependencies() recursively,
  7. The recursive call fails, since it tries to load rmarkdown again while it's already loading.

The simplest workaround to this issue is to load rlang up-front, e.g. in your ~/.Rprofile. Unravelling this is probably going to take some extra thinking on our side.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 7, 2022

For reference:

Tracing .rs.parsePackageDependencies(contents, extension) on entry 
Dotted pair list of 45
 $ : language .rs.rpc.discover_package_dependencies("AB62C144", ".Rmd")
 $ : language .rs.discoverPackageDependencies(docId, fileType)
 $ : language .rs.parsePackageDependencies(contents, extension)
 $ : language requireNamespace("rmarkdown", quietly = TRUE)
 $ : language tryCatch(loadNamespace(package, ...), error = function(e) e)
 $ : language tryCatchList(expr, classes, parentenv, handlers)
 $ : language tryCatchOne(expr, names, parentenv, handlers[[1L]])
 $ : language doTryCatch(return(expr), name, parentenv, handler)
 $ : language loadNamespace(package, ...)
 $ : language namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()),      versionCheck = vI[[j]]), i[[2L]| __truncated__
 $ : language asNamespace(ns)
 $ : language loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
 $ : language namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]),      from = package)
 $ : language loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
 $ : language runHook(".onLoad", env, package.lib, package)
 $ : language tryCatch(fun(libname, pkgname), error = identity)
 $ : language tryCatchList(expr, classes, parentenv, handlers)
 $ : language tryCatchOne(expr, names, parentenv, handlers[[1L]])
 $ : language doTryCatch(return(expr), name, parentenv, handler)
 $ : language fun(libname, pkgname)
 $ : language run_on_load()
 $ : language callback()
 $ : language local({     if (ns_exports_has("cli", "builtin_theme")) { ...
 $ : language eval.parent(substitute(eval(quote(expr), envir)))
 $ : language eval(expr, p)
 $ : language eval(expr, p)
 $ : language eval(quote({     if (ns_exports_has("cli", "builtin_theme")) { ...
 $ : language eval(quote({     if (ns_exports_has("cli", "builtin_theme")) { ...
 $ : language cli::builtin_theme()
 $ : language detect_dark_theme(dark)
 $ : language tryCatch({     if (dark == "auto") { ...
 $ : language tryCatchList(expr, classes, parentenv, handlers)
 $ : language tryCatchOne(expr, names, parentenv, handlers[[1L]])
 $ : language doTryCatch(return(expr), name, parentenv, handler)
 $ : language rstudioapi::getThemeInfo()
 $ : language callFun("getThemeInfo")
 $ : language do.call(f, args)
 $ : language (function ()  { ...
 $ : language .rs.rpc.discover_package_dependencies("51AA4733", ".Rmd")
 $ : language .rs.discoverPackageDependencies(docId, fileType)
 $ : language .rs.parsePackageDependencies(contents, extension)
 $ : language .doTrace(str(sys.calls()), "on entry")
 $ : language eval.parent(exprObj)
 $ : language eval(expr, p)
 $ : language eval(expr, p)
Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 7, 2022

One potential way to resolve this on the RStudio side -- in this call:

.rs.addJsonRpcHandler("discover_package_dependencies", function(docId, fileType)
{
available <- .rs.availablePackages()
ready <- !is.null(available$value)
packages <- .rs.discoverPackageDependencies(docId, fileType)
list(ready = .rs.scalar(ready), packages = packages)
})

Add a check of the form:

loading <- dynGet("__NameSpacesLoading", NULL)
if (!is.null(loading))
  # return some proxy value

This is how R itself detects cyclic namespace loading; e.g.

https://github.com/wch/r-source/blob/ab26cd7a4bb2f109fe614fcedd5857d6028394d4/src/library/base/R/namespace.R#L193-L199

A somewhat heavier hammer would be a similar approach, but refuse to run any RPC methods whenever we're loading a package namespace. I'm not positive where we'd make that check off-hand, though.

@kevinushey kevinushey added triage and removed qa repro labels Jul 7, 2022
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 7, 2022

Adding to triage as this is probably a candidate for a SW patch; given that it has a fairly simple workaround I don't think it's enough to hold up the release.

@mikebessuille
Copy link
Contributor

@mikebessuille mikebessuille commented Jul 7, 2022

I agree, this shouldn't hold up the SW release but could be considered for a patch.

@zonghongz
Copy link

@zonghongz zonghongz commented Jul 9, 2022

I am just curious, why after restoring the older version of rlang1.0.2 instead of rlang1.0.3, the problem disappears, why just restoring to older version of rlang for the time being which I did at the moment.

@mikebessuille mikebessuille assigned jgutman and unassigned ronblum Jul 11, 2022
@mikebessuille mikebessuille added the backport Issues whose associated fixes will need to be backported for a previous release. label Jul 11, 2022
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 14, 2022

I am just curious, why after restoring the older version of rlang1.0.2 instead of rlang1.0.3, the problem disappears, why just restoring to older version of rlang for the time being which I did at the moment.

The newest release of rlang does some work when it's loaded that older versions of rlang did not, and that's interacting in an unfortunate way with RStudio on startup.

@stefanocasirati
Copy link

@stefanocasirati stefanocasirati commented Jul 22, 2022

Another potential way to solve this error is to create a new R studio project.

@jgutman
Copy link
Contributor

@jgutman jgutman commented Jul 22, 2022

@fgeeri
Copy link

@fgeeri fgeeri commented Jul 25, 2022

The error does appear fixed in 2022.11.0-daily+78 👍

Deleting the .Rproj.user folder didn't solve the problem for me in 2022.07.0+548, but downgrading rlang using remotes::install_version("rlang", "1.0.2") also removes the error message, so I'll use that until the RStudio update is released.

@ronblum
Copy link
Contributor

@ronblum ronblum commented Jul 27, 2022

@fgeeri Thank you for testing this! I'm glad to hear that it's working in the version currently in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Issues whose associated fixes will need to be backported for a previous release. bug projects
Projects
None yet
Development

No branches or pull requests

10 participants