Yue-Jiang / pzfx

Read and write 'Graphpad Prism' '.pzfx' files in R
https://yue-jiang.github.io/pzfx/
Other
14 stars 5 forks source link

Adding a parameter for digits displayed #16

Closed nickp60 closed 2 years ago

nickp60 commented 2 years ago

Hi @Yue-Jiang, thanks for writing this package! Would it be possible to add an parameter for setting the decimals displayed by default in the write_fzfx file? The default of 0 has caused some confusion when circulating files to collaborators. Perhaps there could be some logic for using 0 if all values are coercible to ints, otherwise use more decimals either with some logic based on the actual data or via a function parameter.

nickp60 commented 2 years ago

This isn't extensively tested but something like

 ret <- lapply(seq_len(length(x_lst)), function(i) {
    this_df <- x_lst[[i]]
    # check type
    all_ints <-all(sapply(this_df[,2:ncol(this_df)], function(n){
      isTRUE(all.equal(as.integer(n), n))}))
    cols <- lapply(seq_len(ncol(this_df)), function(c) {
      structure(
        list(
          "Title"=list(colnames(this_df)[c]),
          "Subcolumn"=subcol_helper(this_df[, c, drop=TRUE])
        ),
        Width="89",
        Decimals=ifelse(all_ints, "0", "2"),
        Subcolumns="1"
      )
    })
# and so on
}

This checks if all the columns (except for the first one which is often used for x_col ) are coercible to ints, and if not sets 2 decimals for the output display.

Yue-Jiang commented 2 years ago

thanks for the suggestion - i implemented an option to set number of digits in the master branch. let me know if it works for you and feel free to reopen if not. i'll prepare a cran update soonish.