Skip to content

Conversation

zeehio
Copy link
Contributor

@zeehio zeehio commented Nov 2, 2022

This one is beautiful

Create a zip file under outdir/test.zip with "a.txt", when "a.txt" is found on a different folder:

mkdir "outdir"
mkdir "where-a.txt-is-saved"
touch "where-a.txt-is-saved/a.txt"

If we do it like:

zip::zip(
  zipfile = file.path(normalizePath("outdir", mustWork=TRUE), "test.zip"),
  files = c("a.txt"),
  root = "where-a.txt-is-saved"
)

normalizePath() will fail because it will be evaluated when it is first used, and this is in zip:::zip_internal() after we have changed the working directory to root.

Here we force the evaluation of zipfile before changing the directory.

I love this delayed evaluation things 😃

If we use:

zip::zip(
  zipfile = file.path(normalizePath("outdir", mustWork=TRUE), "test.zip"),
  files = c("a.txt"),
  root = "where-a.txt-is-saved"
)

`normalizePath()` will fail because it will be evaluated when
it is first used, and this is in `zip:::zip_internal()` after we
have changed the working directory to `root`.

Here we force the evaluation of zipfile before changing the
directory
zeehio added a commit to sipss/AlpsNMR that referenced this pull request Nov 2, 2022
After fixing

- r-lib/zip#91
- r-lib/zip#92

The zip package works reliably for me again
@gaborcsardi
Copy link
Member

Great catch! Thanks again!

@gaborcsardi gaborcsardi merged commit 5a85195 into r-lib:main Nov 2, 2022
@zeehio
Copy link
Contributor Author

zeehio commented Nov 2, 2022

You're welcome. I love doing this :-)

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

Successfully merging this pull request may close these issues.

2 participants