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

Accessors/getters for DCElement objects #15

Closed
mpadge opened this issue May 18, 2022 · 1 comment
Closed

Accessors/getters for DCElement objects #15

mpadge opened this issue May 18, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request user support
Milestone

Comments

@mpadge
Copy link

mpadge commented May 18, 2022

In the absence of any accessors for DCElement objects, I would expect the only available method of simply naming them to return the actual objects. This leads to the following unexpected behaviour:

library(atom4R)
packageVersion ("atom4R")
#> [1] '0.2.9999'

a0 <- DCAvailable$new (value = FALSE)
ls (a0) # okay
#>  ... expected output

d <- atom4R::DCEntry$new ()
d$addDCAvailable ("01-01-0001")
d$validate ()
#> [atom4R][INFO] Object 'DCEntry' is VALID according to Atom XML schemas!
#> [1] TRUE
a1 <- d$available
ls (a1)
#> Error in list2env(list(<environment>), NULL, <environment>): names(x) must be a character vector of the same length as x

Created on 2022-05-18 by the reprex package (v2.0.1)

Happens because of this line:

self[[term]][[length(self[[term]])+1]] <- elem

Everything is embedded within a list, and trying to access elements as $<element> does not behave as expected. It would arguably be safer to provide accessor methods to (1) enable easy and systematic access; and (2) avoid unexpected behaviour like this.

@eblondel
Copy link
Owner

eblondel commented May 18, 2022

There is no 'getter' accessor, if i understand well what you mean by accessor. We can add some basic getter method for DCElement if needed to facilitate getting some element based on field. Assuming value is what defines the unicity of the element, we might name the list, but it's not always the case, as we may have xml attributes. I will look into that and let you know

@eblondel eblondel changed the title Accessors for DCElement objects Accessors/getters for DCElement objects May 18, 2022
@eblondel eblondel self-assigned this May 18, 2022
@eblondel eblondel added enhancement New feature or request user support labels May 18, 2022
@eblondel eblondel added this to the 0.3 milestone May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user support
Projects
None yet
Development

No branches or pull requests

2 participants