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

check_if_installed() issue on R old-release? #804

Closed
strengejacke opened this issue Sep 12, 2023 · 11 comments · Fixed by #805
Closed

check_if_installed() issue on R old-release? #804

strengejacke opened this issue Sep 12, 2023 · 11 comments · Fixed by #805
Labels
3 investigators ❔❓ Need to look further into this issue

Comments

@strengejacke
Copy link
Member

@rempsyc @etiennebacher @IndrajeetPatil Not sure what's going on, it seems we have no issues on old-R for insight, however, in other packages, we have:

https://github.com/easystats/parameters/actions/runs/6151829558/job/16692707814

Error in mapply(FUN = f, ..., SIMPLIFY = FALSE): zero-length inputs cannot be mixed with those of non-zero length

The affected code seems to be this part:

} else if (!is.null(minimum_version)) {
needs_update <- unlist(Map(function(p, m) {
if (is.na(m)) {
FALSE
} else {
utils::packageVersion(p) < package_version(m)
}
}, package, minimum_version))

My first guess was that package_version() causes issues with old-R, but then it would fail for insight as well, which is not happening. Another guess is that the function that checks for dependency-versions has some issues, but I'm not sure why?

.get_dep_version <- function(dep, pkg = utils::packageName()) {
suggests_field <- utils::packageDescription(pkg, fields = "Suggests")
suggests_list <- unlist(strsplit(suggests_field, ",", fixed = TRUE))
out <- lapply(dep, function(x) {
dep_string <- grep(x, suggests_list, value = TRUE, fixed = TRUE)
dep_string <- dep_string[which.min(nchar(dep_string))]
dep_string <- unlist(strsplit(dep_string, ">", fixed = TRUE))
gsub("[^0-9.]+", "", dep_string[2])
})
if (all(is.na(out))) {
out <- NULL
}
unlist(out)
}

Any ideas?

@strengejacke strengejacke added the 3 investigators ❔❓ Need to look further into this issue label Sep 12, 2023
strengejacke added a commit that referenced this issue Sep 12, 2023
@rempsyc
Copy link
Member

rempsyc commented Sep 12, 2023

Probably .get_dep_version is the issue, I'll look into it

@strengejacke
Copy link
Member Author

See current changes I made. It seems that if no version was given in the description, an element of length 0 was returned, and Map() got package with a string element, and minimum_version was of length 0, that's why Map() failed.

This should be fixed now, but I wonder why tests did not fail for insight?

@rempsyc
Copy link
Member

rempsyc commented Sep 12, 2023

Weird thing is that it seems to work OK on macOS, Windows, and ubuntu release and oldrel, but not ubuntu oldrel-2 and oldrel-3. I'd like to troubleshoot this but I only have access to a Windows machine... What's the recommended approach in these scenarios?

In any case, it seems like the Map call that fails on line 74 uses the minimum_version object created through .get_dep_version, so it must not return a valid result in some situations like for parameters. The Map call checks whether m (the minimum version) is missing through is.na(). But if m is NULL, then length(is.na(NULL)) = 0 for some but not others for lists, which could explain zero-length inputs cannot be mixed with those of non-zero length?

@rempsyc
Copy link
Member

rempsyc commented Sep 12, 2023

Thanks, that should settle it. The only potential issue is that by setting minimum_version to NULL for old R releases, the DESCRIPTION file won't be checked and people may not have the correct version installed. However, before this automatic check, it was also the case that many packages with a minimum version in DESCRIPTION were not specified with a minimum version in check_if_installed, so for those edge cases it does not change much.

@strengejacke
Copy link
Member Author

I think I already removed the check for R version, see https://github.com/easystats/insight/blob/main/R/check_if_installed.R

@strengejacke
Copy link
Member Author

I guess this should be fixes (e.g., performance no longer fails). @easystats/maintainers should we submit a "hotfix" of insight to CRAN? Last update of that package was just a few days ago.

@IndrajeetPatil
Copy link
Member

Yes, but it's a critical enough fix, CRAN won't complain at all. We just need to mention this in CRAN comments doc.

@strengejacke
Copy link
Member Author

Which R versions are oldrel-2 and oldrel-3 (and oldrel)?

@IndrajeetPatil
Copy link
Member

@strengejacke
Copy link
Member Author

hm, it's weird that there's an issue in R 4.1, but not in R 4.2 for Map() when one vector is empty (this is what the error msg was indicating):

See https://github.com/easystats/parameters/actions/runs/6158994652/job/16712908066:

mapply(rep, times = 1:4, x = 4:1)
#> [[1]]
#> [1] 4
#> 
#> [[2]]
#> [1] 3 3
#> 
#> [[3]]
#> [1] 2 2 2
#> 
#> [[4]]
#> [1] 1 1 1 1
mapply(rep, times = 1:4, x = c())
#> list()

Created on 2023-09-13 with reprex v2.0.2

See

Error in `mapply(FUN = f, ..., SIMPLIFY = FALSE)`: zero-length inputs cannot be mixed with those of non-zero length
Backtrace:
    ▆
 1. ├─parameters::standard_error(x) at test-posterior.R:47:2
 2. └─parameters:::standard_error.draws(x) at parameters/R/4_standard_error.R:63:2
 3.   ├─parameters:::.posterior_draws_to_df(model) at parameters/R/methods_posterior.R:49:2
 4.   └─parameters:::.posterior_draws_to_df.draws_list(model) at parameters/R/methods_posterior.R:75:2
 5.     └─insight::check_if_installed("posterior") at parameters/R/methods_posterior.R:87:2
 6.       ├─base::unlist(...) at insight/R/check_if_installed.R:79:4
 7.       └─base::Map(...) at insight/R/check_if_installed.R:79:4
 8.         └─base::mapply(FUN = f, ..., SIMPLIFY = FALSE)

Now, after making changes to check_if_installed(), we no longer see this issue? But I can't believe there was a change in mapply() between R 4.1 and R 4.2, so I wonder why this error only occurred for "old-rel".

@etiennebacher
Copy link
Member

etiennebacher commented Sep 13, 2023

Could be due to https://bugs.r-project.org/show_bug.cgi?id=18164 (implemented in R 4.1.2)? Random guess, it's the only thing I saw in the NEWS of R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 investigators ❔❓ Need to look further into this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants