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

Custom formatting function and handling of na_str when using a formatting function #280

Closed
wants to merge 10 commits into from

Conversation

iaugusty
Copy link
Collaborator

Please find some proposed extra features for formatters package.

main features of custom formatting function:

  • xx notation not restricted to predefined ones
  • For 2 and 3-d stats, the precision of each stat does not have to be the same to all, eg xx.x (xx.xx) for mean (sd)
  • flexible string notation, not restricted to predefined strings

format_value: also allow na_str to be passed onto a custom formatting function when na_str is a parameter of the function

We are open to other proposals for the naming of the proposed custom functions.
Also open to discuss anything else included in this PR.

Copy link
Contributor

github-actions bot commented Apr 29, 2024

CLA Assistant Lite bot ✅ All contributors have signed the CLA

@iaugusty
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

DESCRIPTION Outdated
@@ -35,6 +36,8 @@ Suggests:
r2rtf (>= 0.3.2),
rmarkdown (>= 2.19),
stringi (>= 1.6),
stringr (>= 1.5.0),
tern (>= 0.9.3),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a circular dependency we need to avoid also from suggests

DESCRIPTION Outdated
@@ -35,6 +36,8 @@ Suggests:
r2rtf (>= 0.3.2),
rmarkdown (>= 2.19),
stringi (>= 1.6),
stringr (>= 1.5.0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did a lot of work to avoid importing {stringr} and having only {stringi} in suggests so to have a lighter dep tree as this package is the basis of much of what we do. We have already implemented some ways to read in any xx input, we just lacked the time to add it to {formatters}

DESCRIPTION Outdated
@@ -25,7 +25,8 @@ Depends:
Imports:
checkmate (>= 2.1.0),
grid,
htmltools (>= 0.5.3)
htmltools (>= 0.5.3),
tidytlg (>= 0.1.4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports in this package should be very limited. Where is it needed? we usually add {pkg}:: everywhere we use external packages in all our packages

NAMESPACE Outdated
@@ -153,6 +157,7 @@ importFrom(grid,unit)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(stats,na.omit)
importFrom(tidytlg,roundSAS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt it possible to copy? it is probably not worth the import

DESCRIPTION Outdated
@@ -1,6 +1,6 @@
Package: formatters
Title: ASCII Formatting for Values and Tables
Version: 0.5.6.9002
Version: 0.5.6.9003
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will happen automatically once we merge the PR ;) could you revert this?

R/jjcsformats.R Outdated
#' @examples
#' jjcsformat_xx_SAS <- jjcs_format_xx_fct(roundmethod="SAS")
#' jjcsformat_xx <- jjcsformat_xx_SAS
#' format_value(c(1.453),jjcsformat_xx("xx.xx"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' format_value(c(1.453),jjcsformat_xx("xx.xx"))
#' format_value(c(1.453), jjcsformat_xx("xx.xx"))

Please use a styler to fix these issues (they will not pass the tests, too, I think)

R/jjcsformats.R Outdated
#' format_value(c(1.453),jjcsformat_xx("xx.xx"))
#' format_value(c(1.453,2.45638),jjcsformat_xx("xx.xx (xx.xxx)"))
#'
jjcs_format_xx_fct <- function (roundmethod=c("SAS","R"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jjcs_format_xx_fct <- function (roundmethod=c("SAS","R"))
jjcs_format_xx_fct <- function(round_method = c("SAS", "R"))

We use snake case fore all our variables and fnc. Camel case ONLY for Classes

R/jjcsformats.R Outdated

fnct <- function(str){

if (stringr::str_detect(str,stringr::fixed("xxx."))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use stringi or base R instead of stringr. I know it seems tedious but the stringr footprint is much larger

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be the most tricky one, I'll look into this to use stringi instead

R/jjcsformats.R Outdated
Comment on lines 63 to 66
format(roundfunc(x, digits = ifelse(length(y) >
1, nchar(y[2]), 0)),nsmall = ifelse(length(y) >
1, nchar(y[2]), 0))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use styler for correct spacing

R/jjcsformats.R Outdated
return("-")
}

tern:::assert_proportion_value(fraction, include_boundaries = TRUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use internals of other packages in general. In this case we absolutely want to avoid circular dependencies




# expect_identical(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code is not allowed in testthat

R/jjcsformats.R Outdated
#' roundSAS comes from this Stack Overflow post https://stackoverflow.com/questions/12688717/round-up-from-5
#' * `R`: the underlying rounding method is `round`
#'
#' @return `jjcs_format_xx_fct()` format function that can be used in rtables formatting calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why jjcs? I think these functions may well be of general use, so probably better to have a user-friendly name for these format functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jjcs was coming from our internal project, I agree that we should come up with a better name for this, if you would have any suggestions, these would be more than welcome

@iaugusty iaugusty closed this by deleting the head repository May 28, 2024
@iaugusty
Copy link
Collaborator Author

@Melkiades I reforked the repository to get the latest version of formatters, how do I re-open the current PR?

@iaugusty
Copy link
Collaborator Author

x

@iaugusty
Copy link
Collaborator Author

@Melkiades Shall I just start a new PR, or shall I wait until the truetype font PR is completed?

@Melkiades
Copy link
Contributor

, how do I re-open the current PR?

I think it is better to solve all the issue on this PR (even if you want to create a new one) so I can keep track of changes. When you need to update your local clone branch with main it is enough you git pull and main from the original repo should be tracked so no need to close and reopen

@iaugusty
Copy link
Collaborator Author

As I had deleted my fork, the pull request was closed.
I have reforked, and commited my changes. However, as the pull request was closed, the below "reopen and comment" button states "the repository that submitted this pull request has been deleted", it doesn't recognize my new reforked version.
Do you know an alternative method in github where I can reopen the PR?

@Melkiades
Copy link
Contributor

As I had deleted my fork, the pull request was closed. I have reforked, and commited my changes. However, as the pull request was closed, the below "reopen and comment" button states "the repository that submitted this pull request has been deleted", it doesn't recognize my new reforked version. Do you know an alternative method in github where I can reopen the PR?

I do not know! Try to address my comments and I will review again. I would wait, though for resubmission as soonish you should have rights to branch ;)

fyi @cicdguy @shajoezhu

@cicdguy
Copy link
Contributor

cicdguy commented May 28, 2024

@iaugusty and @gmbecker - you both should be receiving 5 invitations in the mailbox that is associated with your GitHub accounts. One each for tern, formatters, rtables, rlistings, and scda.test. On accepting these invitations, you should have write access to these repos, so you'll no longer need to fork going forward.

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

Successfully merging this pull request may close these issues.

3 participants