3

Context

I've been developing a proprietary package (call it "my_pkg") with vignettes, in RStudio with the latest version (4.1.1) of R. I'm working on a Lenovo ThinkPad with the following software

       sysname        release        version       machine
     "Windows"       "10 x64"  "build 19043"      "x86-64"

as provided by Sys.info().

Until recently, my devtools workflow has been reasonably smooth (with one occasional exception). However, I've begun to encounter a very puzzling error, which occurs under conditions virtually identical to those beforehand, when the workflow proceeded without issue.

Despite the fact that my vignettes always built successfully before, and I have not edited them in the meantime, the build now fails for architecturally specific reasons...

Error : package 'my_pkg' is not installed for 'arch = x64'

...when and only when I include the vignettes in the build.

I have reinstalled R (and Rtools and RStudio) from scratch, reinstalled devtools (and its dependencies), and "rewound" my project to the last Git commit at which devtools::check() succeeded. I have also walked through extensive troubleshooting with responders like @SteffenMoritz and @Alexis, for whom I have appended further information in the section Info by Request.

Unfortunately, nothing has worked.

Failure With devtools::check()

When I run devtools::check(), everything starts promisingly...

i Updating my_pkg documentation
i Loading my_pkg
Writing NAMESPACE
Writing NAMESPACE
-- Building --------------------------------------------------------------------------------- my_pkg --
Setting env vars:
* CFLAGS    : -Wall -pedantic
* CXXFLAGS  : -Wall -pedantic
* CXX11FLAGS: -Wall -pedantic
-------------------------------------------------------------------------------------------------------
√  checking for file 'C:\Users\greg\Workspace\R\Packages\my_pkg/DESCRIPTION' ...
-  preparing 'my_pkg': (733ms)
√  checking DESCRIPTION meta-information ... 
-  installing the package to build vignettes
         -----------------------------------
-  installing *source* package 'my_pkg' ...
   ** using staged installation
   ** R
   ** inst
   ** byte-compile and prepare package for lazy loading
   ** help
   *** installing help indices
     converting help for package 'my_pkg'
       finding HTML links ... done 
       foo                                     html
       my_pkg-package                          html
   *** copying figures
   ** building package indices
   ** installing vignettes
   ** testing if installed package can be loaded from temporary location

...until the step testing if installed package can be loaded from temporary location. Here an error occurs:

   Error : package 'my_pkg' is not installed for 'arch = x64'
   Error: loading failed
   Execution halted
   ERROR: loading failed
-  removing 'C:/Users/greg/AppData/Local/Temp/RtmpSaabgx/Rinst332419517258/my_pkg'
         -----------------------------------
   ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> ** building package indices
E> ** installing vignettes
E> ** testing if installed package can be loaded from temporary location
E> Error : package 'my_pkg' is not installed for 'arch = x64'
E> Error: loading failed
E> Execution halted
E> ERROR: loading failed
E> * removing 'C:/Users/greg/AppData/Local/Temp/RtmpSaabgx/Rinst332419517258/my_pkg'
E>       -----------------------------------
E> ERROR: package installation failed
Type .Last.error.trace to see where the error occurred

The .Last.error.trace suggests an issue with pkgbuild specifically:

> .Last.error.trace

 Stack trace:

 1. devtools::check()
 2. withr::with_envvar(pkgbuild::compiler_flags(FALSE), action = "prefix",  ...
 3. base:::force(code)
 4. pkgbuild::build(pkg$path, tempdir(), args = build_args, quiet = quiet,  ...
 5. withr::with_temp_libpaths(rcmd_build_tools(options$cmd, c(options$path,  ...
 6. base:::force(code)
 7. pkgbuild:::rcmd_build_tools(options$cmd, c(options$path, options$args),  ...
 8. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env,  ...
 9. withr::with_path(rtools_path(), code)
 10. base:::force(code)
 11. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE,  ...
 12. callr:::run_r(options)
 13. base:::with(options, with_envvar(env, do.call(processx::run,  ...
 14. base:::with.default(options, with_envvar(env, do.call(processx::run,  ...
 15. base:::eval(substitute(expr), data, enclos = parent.frame())
 16. base:::eval(substitute(expr), data, enclos = parent.frame())
 17. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 18. base:::force(code)
 19. base:::do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 20. (function (command = NULL, args = character(), error_on_status = TRUE,  ...
 21. throw(new_process_error(res, call = sys.call(), echo = echo,  ...

I have no clue as to why the architecture

Error : package 'my_pkg' is not installed for 'arch = x64'

should be an issue only now. There have been no substantive changes to my computer.

Despite the message package installation failed, and despite the fact that I've run devtools::check() rather than devtools::install(), the package acts as if it were "halfway" installed! I can type my_p in the console, and RStudio will autocomplete my_pkg; and I can then type my_pkg:: and RStudio will supply the standard autocompletion list of the functions in my_pkg, which are all available.

However, typing my_pkg:: not only summons the @exported functions but also exposes my internal functions and data, as if I had typed my_pkg:::!

Success With devtools::install() or devtools::build(vignettes = FALSE)

Oddly, when I actually run devtools::install(), or comparably devtools::build_vignettes(vignettes = FALSE), the process completes without a hitch!

√  checking for file 'C:\Users\greg\Workspace\R\Packages\my_pkg/DESCRIPTION' ...
-  preparing 'my_pkg': (640ms)
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts (384ms)
-  checking for empty or unneeded directories
   Removed empty directory 'my_pkg/inst/libs'
   Omitted 'LazyData' from DESCRIPTION
-  building 'my_pkg_0.0.0.9000.tar.gz'
   
Running "C:/Users/greg/R/bin/x64/Rcmd.exe" INSTALL \
  "C:\Users\greg\AppData\Local\Temp\Rtmpozvh26/my_pkg_0.0.0.9000.tar.gz" --install-tests 
* installing to library 'C:/Users/greg/R/library'
* installing *source* package 'my_pkg' ...
** using staged installation
** R
** inst
** tests
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'my_pkg'
    finding HTML links ... done
       foo                                     html
       my_pkg-package                          html
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (my_pkg)
Making 'packages.html' ... done

Now, the autocompletion works entirely as expected, and only the appropriate functions are exposed by my_pkg:: and my_pkg::: respectively.

Failure With devtools::install(build_vignettes = TRUE) or devtools::build()

Yet there is one further plot twist. When I use devtools::install(build_vignettes = TRUE), or comparably devtools::build(), I get a similar error to that with devtools::check():

√  checking for file 'C:\Users\greg\Workspace\R\Packages\my_pkg/DESCRIPTION' ...
-  preparing 'my_pkg': (672ms)
√  checking DESCRIPTION meta-information ... 
-  installing the package to build vignettes
         -----------------------------------
-  installing *source* package 'my_pkg' ...
   ** using staged installation
   ** R
   ** inst
   ** byte-compile and prepare package for lazy loading
   ** help
   *** installing help indices
     converting help for package 'my_pkg'
       finding HTML links ... done
       foo                                     html
       my_pkg-package                          html
   *** copying figures
   ** building package indices
   ** installing vignettes
   ** testing if installed package can be loaded from temporary location

   Error : package 'my_pkg' is not installed for 'arch = x64'
   Error: loading failed
   Execution halted
   ERROR: loading failed
-  removing 'C:/Users/greg/AppData/Local/Temp/RtmpM7RbHr/Rinst504119422cd/my_pkg'
         -----------------------------------
   ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> ** building package indices
E> ** installing vignettes
E> ** testing if installed package can be loaded from temporary location
E> Error : package 'my_pkg' is not installed for 'arch = x64'
E> Error: loading failed
E> Execution halted
E> ERROR: loading failed
E> * removing 'C:/Users/greg/AppData/Local/Temp/RtmpM7RbHr/Rinst504119422cd/my_pkg'
E>       -----------------------------------
E> ERROR: package installation failed
Type .Last.error.trace to see where the error occurred

Success With devtools::build_vignettes()

Bizarrely, despite the issues above with building vignettes, everything somehow runs smoothly when I call devtools::build_vignettes() sans arguments or with dependencies = TRUE:

i Building my_pkg vignettes
√ Creating 'doc/'
√ Adding '^doc$' to '.Rbuildignore'
√ Setting active project to '<no active project>'
√ Adding '/doc/' to '.gitignore'
√ Setting active project to '<no active project>'
i Moving backstory.html, intro.html, library.html, template.html, usage.html, backstory.R, intro.R, library.R, template.R, and usage.R to doc/
i Copying backstory.Rmd, intro.Rmd, library.Rmd, template.Rmd, and usage.Rmd to doc/
√ Creating 'Meta/'
√ Adding '^Meta$' to '.Rbuildignore'
√ Setting active project to '<no active project>'
√ Adding '/Meta/' to '.gitignore'
√ Setting active project to '<no active project>'
i Building vignette index

Note

Assuming that the fault was mine, and that I had unwittingly introduced an issue somewhere within my R project, I switched to an entirely different Git branch. The most recent commit to this branch had passed devtools::check() with flying colors. However, even after switching over to this "safe" branch, those same issues continued!

Between that last successful check and when the issues began, I made no updates to:

  • R itself
  • RStudio
  • Any R packages
  • My computer's software (with the exception of a minor anti-malware update from Microsoft).
  • My computer's hardware

Likewise, the vignettes have been present since far earlier in the project.

Conclusion

I'm hoping to roll out a proof of concept for my_pkg in the rather near future, and the vignettes are quite essential to its usability.


Info by Request

Since "my_pkg" is proprietary, I here anonymize my personal and organizational information (names, filepaths, etc.) as above.

For @SteffenMoritz

Would you mind sharing your DESCRIPTION file and the vignette header/meta information?

The DESCRIPTION file:

Package: my_pkg
Title: Proprietary Package for My Org
Version: 0.0.0.9000
Authors@R: 
    person(given = "Greg",
           family = "Lastname",
           role = c("aut", "cre"),
           email = c("glastname@myorg.com"))
Description: The `my_pkg` package is a proprietary project for My Org,
    and as such I have changed the names to project the innocent.
License: file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
URL: https://github.com/myorg/my_pkg
BugReports: https://github.com/my_org/my_pkg/issues
Suggests: 
    knitr,
    rmarkdown,
    testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends: 
    R (>= 2.10)

The vignette headers:

  • intro.Rmd:
---
title: "A Catchphrase!"
author: "Gregory Lastname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Catchphrase!}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  # Show no output.
  eval = FALSE, results = "hide",
  # Show no dialog.
  message = FALSE, warning = FALSE,
  # Show no errors.
  error = TRUE, purl = FALSE,
  # Default format.
  collapse = TRUE, comment = "#>"
)
    ```
  • backstory.Rmd:
---
title: "A Reference, to Science Fiction"
author: "Gregory Lastname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Reference, to Science Fiction}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  # Show no output.
  eval = FALSE, results = "hide",
  # Show no dialog.
  message = FALSE, warning = FALSE,
  # Show no errors.
  error = TRUE, purl = FALSE,
  # Default format.
  collapse = TRUE, comment = "#>"
)
    ```
  • library.Rmd
---
title: "A Generic One-Liner"
author: "Gregory Lastname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Generic One-Liner}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  # Show no output.
  eval = FALSE, results = "hide",
  # Show no dialog.
  message = FALSE, warning = FALSE,
  # Show no errors.
  error = TRUE, purl = FALSE,
  # Default format.
  collapse = TRUE, comment = "#>"
)
    ```
  • template.Rmd
---
title: "A Well-Written Description"
author: "Gregory Lastname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A Well-Written Description}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  # Show no output.
  eval = FALSE, results = "hide",
  # Show no dialog.
  message = FALSE, warning = FALSE,
  # Show no errors.
  error = TRUE, purl = FALSE,
  # Default format.
  collapse = TRUE, comment = "#>"
)
    ```
  • usage.Rmd
---
title: "An Exhortation!"
author: "Gregory Lastname"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{An Exhortation!}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  # Show no output.
  eval = FALSE, results = "hide",
  # Show no dialog.
  message = FALSE, warning = FALSE,
  # Show no errors.
  error = TRUE, purl = FALSE,
  # Default format.
  collapse = TRUE, comment = "#>"
)
    ```

For @Alexis

What do you see if you open the .Rproj file with a text editor?

The my_pkg.Rproj file, as opened in MS Notepad. NOTE: This file has not been modified since the very initial commit.

Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

By request

Does it work if you run R CMD build/INSTALL ... from the command line?

I also built from the command line

greg@CO-GLASTNAME MINGW64 ~/Workspace/R
$ R CMD build C:/Users/greg/Workspace/R/Packages/my_pkg

but I got the same output echoed above:

* checking for file 'C:/Users/greg/Workspace/R/Packages/my_pkg/DESCRIPTION' ... OK
* preparing 'my_pkg':
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
      -----------------------------------
* installing *source* package 'my_pkg' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'my_pkg'
    finding HTML links ... done
    foo                                     html
    my_pkg-package                          html
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error : package 'my_pkg' is not installed for 'arch = x64'
Error: loading failed
Execution halted
ERROR: loading failed
* removing 'C:/Users/greg/AppData/Local/Temp/RtmpgFIc2r/Rinst1cc0231a6b37/my_pkg'
      -----------------------------------
ERROR: package installation failed
4

2 回答 2

3

你可能是对的,这是小插图的问题。(但我当然不能 100% 确定,因为我不知道你的文件)

关于您对check()andinstall()运行的困惑:

RStudio 的“构建和重新加载不会构建小插曲”

这就是为什么您可能必须运行 devtools::install() 才能得到错误。

我将向您发布一些最有可能与小插图有关的问题(这里也是一个很好的更长的教程):

首先检查以下几点:

  1. 该目录称为vignettes/,而不是vignettes/。

  2. 检查 .Rbuildignore 是否未涵盖晕影

  3. 确保您拥有必要的小插图元数据(乍一看似乎不错)

这些东西很可能对您来说没问题(但只是为了检查)。

在我看来,最可能的问题是,您的说明文件不包含 .Rmd 小插图的所有必要依赖项

也更好写:

VignetteBuilder: knitr, rmarkdown

在 Suggests 中还保留了 rmarkdown。也为 Suggests 和 VignetteBuilder 编织。

更重要的是(!)您还需要在 .Rmd 文件中使用的包Suggests。由于我假设您使用的是 RMarkdown,因此您的小插曲中有一些代码。浏览您的代码并查看您正在使用哪些包。小插图使用的任何包都应在DESCRIPTION.

我可以想象这也可能是原因,为什么它似乎工作了一次,然后在没有改变(在你看来)之后它失败了。

可能你在它工作时仍然在后台加载了所有必需的包。所以它没有影响,包在Suggests.

这将是我的第一个猜测,问题可能是什么。如果这不起作用,我会尝试删除小插图,看看是否是某个小插图导致了问题。

于 2021-10-14T11:01:37.713 回答
0

未解决

截至目前,尚未发布解决名义错误的答案。我通过澄清的方式向遇到相同错误的任何用户发布此错误,该错误仍未得到诊断和解决。事实上,即使在通过 Git 重置我的项目并从头开始重新安装 R(以及 Rtools 和 RStudio)之后,该错误仍然存​​在。

感谢@SteffenMoritz@Alexis的顽强调试会话。虽然我们的努力没有成功*,但我感谢他们的时间、努力和友善。任何在类似问题上苦苦挣扎的人都会很好地遵循他们的建议,在答案评论中找到。

我将用我将来可能遇到的任何真正的解决方案来更新这篇文章。

*因此,赏金在到期时留给默认机制(因此减半)。

于 2021-10-21T16:12:29.853 回答