-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
CLA Assistant Lite bot ✅ All contributors have signed the CLA |
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' 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")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."))) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
format(roundfunc(x, digits = ifelse(length(y) > | ||
1, nchar(y[2]), 0)),nsmall = ifelse(length(y) > | ||
1, nchar(y[2]), 0)) | ||
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
tests/testthat/test-jjcsformats.R
Outdated
|
||
|
||
|
||
# expect_identical( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Merge branch 'main' of https://github.com/iaugusty/formatters # Conflicts: # DESCRIPTION
@Melkiades I reforked the repository to get the latest version of formatters, how do I re-open the current PR? |
x |
@Melkiades Shall I just start a new PR, or shall I wait until the truetype font PR is completed? |
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 |
As I had deleted my fork, the pull request was closed. |
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 |
@iaugusty and @gmbecker - you both should be receiving 5 invitations in the mailbox that is associated with your GitHub accounts. One each for |
Please find some proposed extra features for formatters package.
main features of custom formatting function:
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.