Skip to content

Permission denied #329

@ghost

Description

Hi,

The example from the web site fails with a Permission denied error:

> library(pkgnet)
> result <- CreatePackageReport('ggplot2')
INFO [2024-05-17 21:53:46] Creating package report for package ggplot2 with reporters: SummaryReporter, DependencyReporter, FunctionReporter
INFO [2024-05-17 21:53:46] Rendering package report...
Error in file(con, "w") : cannot open the connection
In addition: Warning message:
In file(con, "w") :
  cannot open file 'package_report.knit.md': Permission denied

Explanation: CreatePackageReport calls rmarkdown::render, which in turn calls knitr::knit, to render an Rmd document:

> traceback()
7: file(con, "w")
6: writeLines(enc2utf8(text), con, ..., useBytes = TRUE)
5: write_utf8(res, output)
4: knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
3: rmarkdown::render(input = system.file(file.path("package_report", 
       "package_report.Rmd"), package = "pkgnet"), output_dir = dirname(self$report_path), 
       output_file = basename(self$report_path), quiet = TRUE, params = list(reporters = private$reporters, 
           pkg_name = self$pkg_name))
2: createdReport$render_report()
1: CreatePackageReport("ggplot2")

After some tracing, it's apparent that knitr::knit tries to knit the file pkgnet/package_report/package_report.Rmd, which lies inside the installation directory of pkgnet.

But this means it will try to create the file package_report.knit.md inside the same directory, and this is causing an error: I'm on Linux and my packages are installed as root, therefore the package directory is not writable from user code.

There is a temporary fix: reinstall pkgnet from the user account, which will install in a writable directory (precisely, in ~/R/x86_64-pc-linux-gnu-library/4.4/pkgnet).

However, this is really a bug, no package shall try to write in its installation directory, as it's not supposed to be writable.
A better fix would be to store temporary files where they belong, somewhere in tmp, by using the tempfile function for instance. As suggested here, it may be solved by copying the Rmd file to a temporary directory.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions