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

Fix some suboptimal patterns identified by lintr #434

Merged
merged 9 commits into from
Jul 10, 2024

Conversation

Bisaloo
Copy link
Contributor

@Bisaloo Bisaloo commented Jul 10, 2024

One potential last thing is that find_compress() could use the endsWith() base R function:

rio/R/compression.R

Lines 1 to 35 in 588971f

find_compress <- function(f) {
if (grepl("\\.zip$", f)) {
return(list(file = sub("\\.zip$", "", f), compress = "zip"))
}
if (grepl("\\.tar\\.gz$", f)) {
return(list(file = sub("\\.tar\\.gz$", "", f), compress = "tar.gz"))
}
if (grepl(".tgz$", f)) {
return(list(file = sub("\\.tgz$", "", f), compress = "tar.gz"))
}
if (grepl("\\.tar\\.bz2$", f)) {
return(list(file = sub("\\.tar\\.bz2$", "", f), compress = "tar.bz2"))
}
if (grepl("\\.tbz2$", f)) {
return(list(file = sub("\\.tbz2$", "", f), compress = "tar.bz2"))
}
if (grepl("\\.tar$", f)) {
return(list(file = sub("\\.tar$", "", f), compress = "tar"))
}
if (grepl("\\.gzip$", f)) {
## weird
return(list(file = sub("\\.gzip$", "", f), compress = "gzip"))
}
if (grepl("\\.gz$", f)) {
return(list(file = sub("\\.gz$", "", f), compress = "gzip"))
}
if (grepl("\\.bz2$", f)) {
return(list(file = sub("\\.bz2$", "", f), compress = "bzip2"))
}
if (grepl("\\.bzip2$", f)) {
## weird
return(list(file = sub("\\.bzip2$", "", f), compress = "bzip2"))
}
return(list(file = f, compress = NA_character_))
}

But from my (admittedly limited) testing, it seems that NA_character_ is a possible value for f, leading to the creation of a file named NA. This means endsWith() is not a good fit here.

But is it an explicit design choice to allow NA_character_ or an unexpected side effect?

@Bisaloo
Copy link
Contributor Author

Bisaloo commented Jul 10, 2024

Tests failures are due to r-lib/testthat#1969.

@chainsawriot
Copy link
Collaborator

@Bisaloo Once again, thank you very much for the PR. Most of them LGTM. I still have to actually stress test the removal of the setwd(). Those code is not automatically checked and last time I checked, setwd() must still be there. #319

@chainsawriot
Copy link
Collaborator

For this, NA_character_ is surely an unexpected side effect and should be excluded. So, I think it's safe to use endsWith() here. I will open another issue related to this.

One potential last thing is that find_compress() could use the endsWith() base R function:

rio/R/compression.R

Lines 1 to 35 in 588971f

find_compress <- function(f) {
if (grepl("\\.zip$", f)) {
return(list(file = sub("\\.zip$", "", f), compress = "zip"))
}
if (grepl("\\.tar\\.gz$", f)) {
return(list(file = sub("\\.tar\\.gz$", "", f), compress = "tar.gz"))
}
if (grepl(".tgz$", f)) {
return(list(file = sub("\\.tgz$", "", f), compress = "tar.gz"))
}
if (grepl("\\.tar\\.bz2$", f)) {
return(list(file = sub("\\.tar\\.bz2$", "", f), compress = "tar.bz2"))
}
if (grepl("\\.tbz2$", f)) {
return(list(file = sub("\\.tbz2$", "", f), compress = "tar.bz2"))
}
if (grepl("\\.tar$", f)) {
return(list(file = sub("\\.tar$", "", f), compress = "tar"))
}
if (grepl("\\.gzip$", f)) {
## weird
return(list(file = sub("\\.gzip$", "", f), compress = "gzip"))
}
if (grepl("\\.gz$", f)) {
return(list(file = sub("\\.gz$", "", f), compress = "gzip"))
}
if (grepl("\\.bz2$", f)) {
return(list(file = sub("\\.bz2$", "", f), compress = "bzip2"))
}
if (grepl("\\.bzip2$", f)) {
## weird
return(list(file = sub("\\.bzip2$", "", f), compress = "bzip2"))
}
return(list(file = f, compress = NA_character_))
}

But from my (admittedly limited) testing, it seems that NA_character_ is a possible value for f, leading to the creation of a file named NA. This means endsWith() is not a good fit here.

But is it an explicit design choice to allow NA_character_ or an unexpected side effect?

@chainsawriot
Copy link
Collaborator

@Bisaloo Once again, thank you very much for the PR. Most of them LGTM. I still have to actually stress test the removal of the setwd(). Those code is not automatically checked and last time I checked, setwd() must still be there. #319

OK, This one should be fine.

@chainsawriot
Copy link
Collaborator

@Bisaloo Please add yourself to Authors@R. Then I will merge this.

@chainsawriot chainsawriot merged commit 6547415 into gesistsa:main Jul 10, 2024
7 of 8 checks passed
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