Is there a known problem with downloading files in examples?
Summary: I wonder how to debug a problem with build_site() and downloading to a tempdir().
I'm working on a package that downloads oceanographic data. As I understand it, that's a problem for a package that might have hopes of getting on CRAN.
Some of the functions have a parameter that I call destdir, which is where to save the downloaded files. In my work, that will be ~/data/, for example. But, in my example code, I use tempdir() to get a temporary directory in which to save the files.
This scheme works in practice. And it works within examples, when I run those examples locally, or when I run the "check" action in RStudio.
However, when I try building the package docs with pkgdown::build_site(), I get that a download occurs, but then that gzfile cannot find the file. An example is below.
Warning message:
In gzfile(file, mode) :
cannot open compressed file '/var/folders/8b/l4h64m1j22v5pb7vj049ff140000gn/T//RtmpNry5AV/downlit/base', probable reason 'No such file or directory'
This is odd, because I'm calling it with
destdir <- tempdir("amsr")
file <- dod.amsr(destdir = destdir)
where I'm stating that the text "amsr" ought to be part of the directory name.
I don't really know how to debug this sort of problem. My code (https://github.com/dankelley/dod/) is quite long. Should I try to boil it down and post that, or is there a known problem that can occur with downloads to temporary directories?
AKAIK there's nothing intrinsic to pkgodwn that should prevent this, but as you surmised CRAN will not allow it.
tempdir() doesn't take a pattern as an argument. tempfile() does though. See ?tempdir.
And yes I suggest that you make a minimal package that recapitulates the problem. There are some instructrions for that here.
Thanks, you're right on the mistake about supplying a parameter to tempdir(). That wasn't the problem though. Based on your advice, I made a small project (at https://github.com/dankelley/downloadtest) and found as follows. (Please note that I do not absolutely need this to work, but I really do like making a website with pkgdown because if there are examples that are run, users can see the results. Lots of users prefer that to using the ? mechanism and clicking on the run-code phrase.)
- it builds OK, and it runs OK when I copy-paste to the console and also when I click the run-examples phrase in the docs shown in RStudio
- it checks OK with the RStudio 'check' button
- when I try
pkgdown::build_site()(version 2.1.0 of pkgdown) and I get as follows, which is the same sort of thing I had in my actual project.
Reading man/linesInRemoteFile.Rd
trying URL 'https://raw.githubusercontent.com/dankelley/dod/main/NEWS.md'
Content type 'text/plain; charset=utf-8' length 1613 bytes
==================================================
downloaded 1613 bytes
Warning message:
In gzfile(file, mode) :
cannot open compressed file '/var/folders/8b/l4h64m1j22v5pb7vj049ff140000gn/T//RtmptPkNky/downlit/base', probable reason 'No such file or directory'
Error:
! in callr subprocess.
Caused by error in `build_reference()`:
! Failed to parse Rd in linesInRemoteFile.Rd
Caused by error in `gzfile()`:
! cannot open the connection
ℹ See `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.
I can't see your test repo: https://github.com/dankelley/downloadtest
Is it in private status?
Oh, I'm so sorry about that. I didn't make it in my usual way. It's public now. My apologies for being such a bother.
FYI, my session info is as follows.
> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-apple-darwin20
Running under: macOS 15.0
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Halifax
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
loaded via a namespace (and not attached):
[1] compiler_4.4.1 tools_4.4.1
Closing due to inactivity, please re-open if you are still have an issue.
I'm reopening the issue, since I now have a small repo that demonstrates the problem. (Well, I say "problem" but it might be a problem with me, not pkgdown!!)
The site https://github.com/dankelley/dek2024 has the repo I set up. It builds fine, and I can run the documentation example in the single function (named dek2024, unimaginatively). It produces the following output. All my packages are up-to-date, and I'm using the most recent R release (on a macOS machine).
Please let me know whether this is of any use. I'd be happy to do further tests, of course. And, as I say, it might be a problem of my own devising. One thing: I am now on a different machine than the one where I initially asked the question. However, it was set up by letting the Apple software copy over a "time machine" backup, so I might have inherited something odd with my temporary files.
> pkgdown::build_site()
── Installing package dek2024 into temporary librar
── Initialising site ───────────────────────────────────────────────────────────
Copying <pkgdown>/BS3/assets/bootstrap-toc.css to bootstrap-toc.css
Copying <pkgdown>/BS3/assets/bootstrap-toc.js to bootstrap-toc.js
Copying <pkgdown>/BS3/assets/docsearch.css to docsearch.css
Copying <pkgdown>/BS3/assets/docsearch.js to docsearch.js
Copying <pkgdown>/BS3/assets/link.svg to link.svg
Copying <pkgdown>/BS3/assets/pkgdown.css to pkgdown.css
Copying <pkgdown>/BS3/assets/pkgdown.js to pkgdown.js
── Building pkgdown site for package dek2024 ───────────────────────────────────
Reading from: /Users/kelley/git/dek2024
Writing to: /Users/kelley/git/dek2024/docs
── Sitrep ──────────────────────────────────────────────────────────────────────
✖ Bootstrap 3 is deprecated; please switch to Bootstrap 5.
ℹ Learn more at
<https://www.tidyverse.org/blog/2021/12/pkgdown-2-0-0/#bootstrap-5>.
✖ URLs not ok.
No _pkgdown.yml found.
See details in `vignette(pkgdown::metadata)`.
✔ Favicons ok.
✔ Open graph metadata ok.
✔ Articles metadata ok.
✔ Reference metadata ok.
── Initialising site ───────────────────────────────────────────────────────────
── Building home ───────────────────────────────────────────────────────────────
Writing authors.html
Reading DESCRIPTION
Writing index.html
Writing 404.html
── Building function reference ─────────────────────────────────────────────────
Writing reference/index.html
Reading man/dek2024.Rd
trying URL 'http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=43405&Year=2024&Month=12&timeframe=1&submit=Download+Data'
downloaded 118 KB
Warning message:
In gzfile(file, mode) :
cannot open compressed file '/var/folders/8b/l4h64m1j22v5pb7vj049ff140000gn/T//RtmpXB77aw/downlit/base', probable reason 'No such file or directory'
Error:
! in callr subprocess.
Caused by error in `build_reference()`:
! Failed to parse Rd in dek2024.Rd
Caused by error in `gzfile()`:
! cannot open the connection
ℹ See `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.
PS. sorry, I said 'reopen' but the system is not letting me do that, for some reason. I'm not sure my ssh keys are proper on this machine.