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

Is there a known problem with downloading files in examples? #2774

Open
dankelley opened this issue Sep 7, 2024 · 5 comments
Open

Is there a known problem with downloading files in examples? #2774

dankelley opened this issue Sep 7, 2024 · 5 comments

Comments

@dankelley
Copy link

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?

@jayhesselberth
Copy link
Collaborator

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.

@dankelley
Copy link
Author

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.)

  1. 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
  2. it checks OK with the RStudio 'check' button
  3. 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 connectionSee `$stdout` and `$stderr` for standard output and error.
Type .Last.error to see the more details.

@jayhesselberth
Copy link
Collaborator

I can't see your test repo: https://github.com/dankelley/downloadtest

Is it in private status?

@dankelley
Copy link
Author

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.

@dankelley
Copy link
Author

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  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants