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

should plot_KDE() support numeric vectors and 1-column data frames? #189

Closed
mcol opened this issue Sep 2, 2024 · 3 comments
Closed

should plot_KDE() support numeric vectors and 1-column data frames? #189

mcol opened this issue Sep 2, 2024 · 3 comments

Comments

@mcol
Copy link
Contributor

mcol commented Sep 2, 2024

The docs for 'plot_KDE()' state:

#' @param data [data.frame] or [RLum.Results-class] object (required):
#' for data.frame: two columns: De (values[,1]) and De error (values[,2]).
#' For plotting multiple data sets, these must be provided as
#' list (e.g. list(dataset1, dataset2)).

However, the code accepts also vectors and doesn't actively check that a data.frame contains two columns:

 if(is(data[[i]], "RLum.Results") == FALSE &
         is(data[[i]], "data.frame") == FALSE &
         is.numeric(data[[i]]) == FALSE) {
      .throw_error("Input data must be one of 'data.frame', ",
                   "'RLum.Results' or 'numeric'")

So the following errors can be generated:

plot_KDE(df[, 1])
# Error in data[[i]][, 1:2] : incorrect number of dimensions
plot_KDE(df[, 1, drop = FALSE])
# Error in `[.data.frame`(data[[i]], , 1:2) : undefined columns selected

Do we want to support these uses and update the documentation, or should we start rejecting them?

@mcol mcol added this to the v0.9.25 (autumn CRAN release) milestone Sep 2, 2024
@RLumSK
Copy link
Member

RLumSK commented Sep 2, 2024

Please remove the vector, we only allow what is documented. No idea why it ended up there.

@mcol
Copy link
Contributor Author

mcol commented Sep 2, 2024

We've rediscussed this issue considering that:

  • the current code is already dealing with numeric vectors and 1-column data frames: in such cases, it creates a 2-column data frame by appending a column of NAs
  • however, currently this leads to all rows being removed, as the code calls 'na.exclude()` without checking if the second column was artificially added by us
  • calc_Statistics() throws a warning: "All errors are NA or zero! Automatically set to 10^-9!"

We've reached the following conclusions:

  • we will support numeric vectors and 1-column data frames and update the documentation accordingly
  • instead of adding a column of NAs, we will add a column of very small values, such as 10^(-9) so that the behaviour of calc_Statistics() will not change while silencing the warning

@mcol
Copy link
Contributor Author

mcol commented Sep 3, 2024

Fixed by #194.

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

No branches or pull requests

2 participants