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

Metadata columns in wrong order when some item has no metadata #23

Closed
montesmariana opened this issue Mar 17, 2023 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@montesmariana
Copy link
Collaborator

If there are multiple data objects or collections and one of them has no metadata, the order of the AVU-parts for the existing metadata is wrong: attribute-units-value, i.e. alphabetically.

rirods:::metadata_reorder() is meant to fix this, but it's failing silently when it runs into the empty dataframe of the item with no metadata.

At the bottom of the example I suggest an alternative Map() call for rirods:::metadata_reorder(), although this might also end up linked to #12 (this could be dealt with in a custom printing method).

library(rirods)
library(tibble)
create_irods("http://localhost/irods-rest/0.9.3", "/tempZone/home", overwrite = TRUE)
iauth('rods', 'rods')
# Problem ----
files <- ils(metadata = TRUE)
files
#>                     logical_path      metadata        type
#> 1 /tempZone/home/rods/collection          NULL  collection
#> 2    /tempZone/home/rods/foo.rds foo, baz, bar data_object

# The order of the columns is alphabetical
files$metadata
#> [[1]]
#> data frame with 0 columns and 0 rows
#> 
#> [[2]]
#>   attribute units value
#> 1       foo   baz   bar

# Diagnosis ----
# Silent error in `metadata_reorder()`

# code from `ils()`:
out <- rirods:::irods_rest_call('list', 'GET', list(
  `logical-path` = rirods:::.rirods$current_dir,
  stat = as.integer(FALSE),
  metadata = as.integer(TRUE),
  offset = 0,
  limit = 100
), FALSE)
x <- httr2::resp_body_json(
  out,
  check_type = FALSE,
  simplifyVector = TRUE
)$`_embedded`
x$metadata
#> [[1]]
#> data frame with 0 columns and 0 rows
#> 
#> [[2]]
#>   attribute units value
#> 1       foo   baz   bar

# what `metadata_reorder()` tries to do
Map(function(x) {x <- x[ ,c("attribute", "value", "units")]; x}, x$metadata)
#> Error in `[.data.frame`(x, , c("attribute", "value", "units")): undefined columns selected

# because it's called silently, it doesn't tell us there is an error with the empty dataframe

# Suggestion ----
# replacement for the `Map()` call in `metadata_reorder()`
Map(function(x) {if (length(x) > 0) x[ ,c("attribute", "value", "units")] else x}, x$metadata)
#> [[1]]
#> data frame with 0 columns and 0 rows
#> 
#> [[2]]
#>   attribute value units
#> 1       foo   bar   baz

Created on 2023-03-17 with reprex v2.0.2

MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue May 27, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue May 27, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue May 27, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue May 31, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue May 31, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 1, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 1, 2023
trel pushed a commit that referenced this issue Jun 1, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 1, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 1, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 3, 2023
MartinSchobben added a commit to MartinSchobben/irods_client_library_rirods that referenced this issue Jun 3, 2023
@trel trel added the bug Something isn't working label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants