pkgcache
pkgcache copied to clipboard
`parse_packages()` behaviour with empty file.
Working with JFROG Artifactory, one can occasionally encounter an empty PACKAGES file. I think it's nice to warn when this happens (which is the current behaviour, see below), although an argument can be made for throwing an error. If it remains a warning, it would be nice to make it more specific.
library(pkgcache)
tmp <- tempfile("PACKAGES")
writeLines("", tmp)
parse_packages(tmp)
#> Warning in structure(.x, class = c(.class, "data.frame"), row.names = .set_row_names(.size), : Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
#> Consider 'structure(list(), *)' instead.
#> # A data frame: 0 × 0
Created on 2024-03-08 by the reprex package (v2.0.1)
It could also be zero lines.
The warning is not intentional, TBH I am not sure if an edge case should throw a warning.
Why is a warning useful for you?
In my case I was scanning through all the PACKAGES files in a CRAN-like repository, using parse_packages()
to parse them and combining them into a single data frame (with an annotation column saying which PACKAGES file they came from). The warning alerted me that one of the files was empty (because it was a directory that had been created by accident), although I didn't know what was wrong until I dug into it.
But seeing as this is a very uncommon use case, it's perhaps not worth the warning.
OK, let me think about this at the next pkgcache release.
I am a bit reluctant to add a warning, because I can imagine that some PACKAGES
files are empty, e.g. if you are not serving macOS or Windows binaries from the repo. Although in practice currently the PACKAGES
file is completely missing in this case.