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

Added update_documentation to quickly update everything and generate … #356

Merged
merged 3 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions R/add_CI.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' No default method is available at the moment.
#'
#' @param gg visR object
#' @param gg A ggplot created with visR
#' @param ... other arguments passed on to the method to modify \code{\link[ggplot2]{geom_ribbon}}
#'
#' @examples
Expand Down Expand Up @@ -43,7 +43,6 @@ add_CI <- function(gg, ...){
UseMethod("add_CI", gg)
}

#' @param gg A ggplot created with visR
#' @param alpha aesthetic of ggplot2 \code{\link[ggplot2]{geom_ribbon}}. Default is 0.1.
#' @param style aesthetic of ggplot2 \code{\link[ggplot2]{geom_ribbon}}. Default is "ribbon". An alternative option is "step" that uses a line to display interval bounds.
#' @param linetype aesthetic of ggplot2 \code{\link[ggplot2]{geom_ribbon}}.
Expand Down
3 changes: 1 addition & 2 deletions R/add_CNSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' No default method is available at the moment.
#'
#' @param gg visR object
#' @param gg A ggplot created with visR
#' @param ... other arguments passed on to the method to modify \code{\link[ggplot2]{geom_point}}
#'
#' @examples
Expand Down Expand Up @@ -39,7 +39,6 @@ add_CNSR <- function(gg, ...){
UseMethod("add_CNSR", gg)
}

#' @param gg A ggplot created with visR
#' @param shape aesthetic of ggplot2 \code{\link[ggplot2]{geom_point}}. Default is 3.
#' @param size aesthetic of ggplot2 \code{\link[ggplot2]{geom_point}}. Default is 2.
#'
Expand Down
3 changes: 1 addition & 2 deletions R/add_highlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description S3 method for highlighting a specific strata by lowering the opacity of all other strata.
#'
#' @param gg visR object
#' @param gg A ggplot created with visR
#' @param ... other arguments passed on to the method
#'
#' @examples
Expand Down Expand Up @@ -31,7 +31,6 @@ add_highlight <- function(gg, ...){
UseMethod("add_highlight", gg)
}

#' @param gg A ggsurvfit, ideatlly created with visR
#' @param strata String representing the name and value of the strata to be highlighted as shown in the legend.
#' @param bg_alpha A numerical value between 0 and 1 that is used to decrease the opacity off all strata not chosen to be highlighted in `strata`. The other strata's existing alpha values are multiplied by `bg_alpha` to decrease their opacity, highlighting the target strata. This works on both `colour` and `fill` properties, as for example present after applying `visR::add_CI()`.
#'
Expand Down
3 changes: 1 addition & 2 deletions R/add_quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description Method to add quantile lines to a plot.
#'
#' @param gg visR object
#' @param gg A ggplot created with visR
#' @param ... other arguments passed on to the method to modify \code{\link[ggplot2]{geom_line}}
#'
#' @examples
Expand Down Expand Up @@ -47,7 +47,6 @@ add_quantiles <- function(gg, ...){
UseMethod("add_quantiles", gg)
}

#' @param gg A ggplot created with visR
#' @param quantiles vector of quantiles to be displayed on the probability scale, default: 0.5
#' @param linetype string indicating the linetype as described in the aesthetics of ggplot2 \code{\link[ggplot2]{geom_line}}, default: dashed (also supports "mixed" -> horizontal lines are solid, vertical ones are dashed)
#' @param linecolour string indicating the linetype as described in the aesthetics of ggplot2 \code{\link[ggplot2]{geom_line}}, default: grey, (also supports "strata" -> horizontal lines are grey50, vertical ones are the same colour as the respective strata)
Expand Down
2 changes: 1 addition & 1 deletion R/add_risktable.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' }
#' }
#'
#' @param gg visR plot of class `ggsurvfit` or `ggtidycmprsk`
#' @param gg A ggplot created with visR
#' @param ... other arguments passed on to the method add_risktable
#'
#' @rdname add_risktable
Expand Down
34 changes: 20 additions & 14 deletions R/apply_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@
#'
#' @examples
#'
#' theme <- visR::define_theme(strata = list("SEX" = list("F" = "red",
#' "M" = "blue"),
#' "TRTA" = list("Placebo" = "cyan",
#' "Xanomeline High Dose" = "purple",
#' "Xanomeline Low Dose" = "brown")),
#' fontsizes = list("axis" = 12,
#' "ticks" = 10,
#' "legend_title" = 10,
#' "legend_text" = 8),
#' fontfamily = "Helvetica",
#' grid = list("major" = FALSE,
#' "minor" = FALSE),
#' bg = "transparent",
#' legend_position = "top")
#' theme <- visR::define_theme(
#' strata = list("SEX" = list("F" = "red",
#' "M" = "blue"
#' ),
#' "TRTA" = list("Placebo" = "cyan",
#' "Xanomeline High Dose" = "purple",
#' "Xanomeline Low Dose" = "brown"
#' )
#' ),
#' fontsizes = list("axis" = 12,
#' "ticks" = 10,
#' "legend_title" = 10,
#' "legend_text" = 8),
#' fontfamily = "Helvetica",
#' grid = list("major" = FALSE,
#' "minor" = FALSE
#' ),
#' bg = "transparent",
#' legend_position = "top"
#')
#'
#' @export

Expand Down
3 changes: 1 addition & 2 deletions R/get_COX_HR.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @seealso \code{\link[survival]{coxph}} \code{\link[stats]{update.formula}}
#'
#' @param x S3 object
#' @param x An object of class \code{survfit}
#' @param ... other arguments passed on to the method survival::coxph
#'
#' @rdname get_COX_HR
Expand All @@ -17,7 +17,6 @@ get_COX_HR <- function(x, ...){
}


#' @param x An object of class \code{survfit}
#' @param update_formula Template which specifies how to update the formula of the survfit object \code{\link[stats]{update.formula}}
#'
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/get_quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' @seealso \code{\link[survival]{quantile.survfit}}
#'
#' @param x S3 object
#' @param x An object of class \code{survfit}
#' @param ... other arguments passed on to the method
#'
#' @examples
Expand Down
3 changes: 1 addition & 2 deletions R/get_risktable.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' @seealso \code{\link[survival]{summary.survfit}}
#'
#' @param x object to be passed on to the method
#' @param x an object of class `survfit` or `tidycuminc`
#' @param ... other arguments passed on to the method
#' @return return list of attributes the form the risk table i.e.
#' number of patients at risk per strata
Expand All @@ -17,7 +17,6 @@ get_risktable <- function(x, ...){
UseMethod("get_risktable")
}

#' @param x an object of class `survfit` or `tidycuminc`
#' @param times Numeric vector indicating the times at which the risk set, censored subjects, events are calculated.
#' @param statlist Character vector indicating which summary data to present. Current choices are "n.risk" "n.event"
#' "n.censor", "cum.event", "cum.censor".
Expand Down
3 changes: 1 addition & 2 deletions R/get_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @description S3 method for extracting descriptive statistics across strata.
#' No default method is available at the moment.
#'
#' @param x S3 object
#' @param x An object of class `survfit`
#' @param ... other arguments passed on to the method
#'
#' @rdname get_summary
Expand All @@ -14,7 +14,6 @@ get_summary <- function(x, ...){
UseMethod("get_summary", x)
}

#' @param x An object of class `survfit`
#' @param statlist Character vector containing the desired information to be displayed. The order of the arguments determines the order in which
#' they are displayed in the final result. Default is the strata ("strata"), number of subjects ("records"), number of events ("events"),
#' the median survival time ("median"), the Confidence Interval ("CI"), the Lower Confidence Limit ("UCL") and the Upper Confidence Limit ("UCL").
Expand Down
2 changes: 1 addition & 1 deletion R/tidyme.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @seealso \code{\link[broom]{tidy}}
#'
#' @param x S3 object
#' @param x An S3 object
#' @param ... other arguments passed on to the method
#'
#' @examples
Expand Down
44 changes: 44 additions & 0 deletions R/utils_general.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,47 @@
width = 6,
scientific = FALSE)
}

#' @title Update documentation
Copy link
Collaborator

@ddsjoberg ddsjoberg Apr 23, 2022

Choose a reason for hiding this comment

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

Can you add some details describing the need this function fulfills?

I see it creates a PDF of the help files. Is this something needed given that the package build already includes the PDF?

I personally find the website to be a much much much better representation of the help files compared to the PDFs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have moved it locally and see if we get the request for some documentation in pdf inside the package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI

#'
#' @description This functions generates the documentation for a package if both /man and /documentation folders exist within the project:
#' \itemize{
#' \item{devtools::document(pkg=pkg) is used to generate Rd files}
#' \item{Rd files are rendered using ?'anyfunction' eg ?visR}
#' \item{Documentation is collected within 'pkg'.pdf. This pdf is written to the documentation folder}
#' }
#'
#' @usage update_documentation(pkg = "~/visR")
#'
#' @param pkg Path to package.
#'
#' @return .Rd files inside man/ folder and an updated pdf within the documentation folder.
#' @noRd
#'
#' @examples
#' \dontrun{
#' update_documentation(pkg = "~/visR")
#' }

update_documentation <- function(pkg = "~/visR", fileNm="visR")
{

## Create Rd files document ####
devtools::document(pkg = pkg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, this adds a {devtools} dependency (a pretty big one). If you choose to keep it, it needs to be added to DESCRIPTION

Copy link
Collaborator Author

@SHAESEN2 SHAESEN2 Apr 24, 2022

Choose a reason for hiding this comment

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

Also if it is only for internal usage? I have moved it to my local folder now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. You added a documentation folder. If you keep this folder, it needs to be added to .Rbuildignore to avoid a NOTE on r CMD Check. NOTES on R CMD Check will exclude the package from auto-acceptance on CRAN, and will kick it to a human for review.
    Thanks for the note. I did not realize it.
  1. FYI R 4.2 was released yesterday, and they have added an additional check for using inherits(strata, "list") instead of class(strata) == "list", for example. Perhaps not in this PR, but all these calls will need to be updated. While you're updating, note that inherits(x, c("a", "b")) is equivalent to inherits(x, "a") | inherits(x, "b").
    Will you make an issue for this?
  1. For generic functions like visr(), where the the generic and S3 methods are all documented in a single file–please move all documentation of arguments to the top of the file. This makes it much easier to review, reduces risk of argument doc duplication, and adds parity between the documentation code and the rendered help file (where all documented arguments all appear on top).
    Agree and updated

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also if it is only for internal usage? I have moved it to my local folder now.

Yes, because the code was in the R folder, and was shipped as part of the package, it would need to be listed as a dependency.


## Look for exported functions
tmp <- data.frame(lines = trimws(suppressWarnings(readLines(paste0(pkg, "/NAMESPACE"))), which=("both")), stringsAsFactors = F)
tmp <- data.frame(lines = tmp$lines[which(grepl("export", tmp$lines) == "TRUE")], stringsAsFactors = F)
tmp <- data.frame(lines = gsub("export(", "", tmp$lines, fixed = TRUE))
fcts <- as.vector(gsub(")", "", tmp$lines, fixed = TRUE))

## Render Rd files
for (j in 1:length(fcts)){
eval(parse(text=paste0("?",fcts[j])))
writeLines(paste0("?",fcts[j]))
}

## create pdf
system(paste0("R CMD Rd2pdf ", pkg, "/man --force --no-preview --output='", pkg, "/documentation/", fileNm, ".pdf'"))
}

14 changes: 10 additions & 4 deletions R/utils_visr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@
#'
#' @description This function aligns multiple \code{ggplot} graphs by making them the same width by taking into account the legend width.
#'
#' @param pltlist A list of plots (TODO: provide more detail)
#' @param pltlist A list of plots
#'
#' @return List of \code{ggplot} with equal width.
#'
#' @references \url{https://stackoverflow.com/questions/26159495/align-multiple-ggplot-graphs-with-and-without-legends}
#' @references \url{https://stackoverflow.com/questions/26159495/align-multiple-ggplot-
#' graphs-with-and-without-legends}
#'
#' @examples
#' \donttest{
#'
#' ## create 2 graphs
#' p1 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE), fill = "Age")) +
#' ggplot2::geom_histogram(bins = 15)
#'
#' p2 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE))) +
#' ggplot2::geom_histogram(bins = 15)
#'
#' ## default alignment does not take into account legend size
#' cowplot::plot_grid(plotlist = list(p1,p2), align = "none", nrow=2)
#' cowplot::plot_grid(plotlist = list(p1,p2),
#' align = "none",
#' nrow=2)
#'
#' ## align_plots() takes into account legend width
#' cowplot::plot_grid(plotlist = visR::align_plots(pltlist = list(p1, p2)), align = "none", nrow=2)
#' cowplot::plot_grid(plotlist = visR::align_plots(pltlist = list(p1, p2)),
#' align = "none",
#' nrow=2)
#' }
#' @export

Expand Down
14 changes: 8 additions & 6 deletions R/visr.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#'
#' @seealso \code{\link[ggplot2]{ggplot}}
#'
#' @param x object to be passed on to the method
#' @param x Object of class `survfit`, `attritiontable` or `visr.tidycuminc`

#' @param ... other arguments passed on to the method
#'
#' @rdname visr
Expand All @@ -24,7 +25,6 @@ visr.default <- function(x, ...){
graphics::plot(x)
}

#' @param x Object of class `survfit`
#' @param x_label \code{character} Label for the x-asis. When not specified,
#' the algorithm will look for "PARAM" information inside the list structure
#' of the `survfit` object.
Expand Down Expand Up @@ -332,8 +332,6 @@ visr.survfit <- function(

}

#' @param x Object of class `attritiontable` with each row corresponding to an
#' inclusion step in the cohort and minimally a description and a count column
#' @param description_column_name \code{character} Name of the column containing
#' the inclusion descriptions
#' @param value_column_name \code{character} Name of the column containing the
Expand Down Expand Up @@ -365,9 +363,13 @@ visr.survfit <- function(
#' attrition %>%
#' visr("Criteria", "Remaining N")
#'
#' # Adding more detailed complement descriptions to the "exclusion" part of the CONSORT diagram
#' # Add detailed complement descriptions to the "exclusion" part of the CONSORT diagram
#' # Step 1. Add new column to attrition dataframe
#' attrition$Complement <- c("NA", "Placebo Group", "Younger than 75 years", "Non-White", "Male")
#' attrition$Complement <- c("NA",
#' "Placebo Group",
#' "Younger than 75 years",
#' "Non-White",
#' "Male")
#'
#' # Step 2. Define the name of the column in the call to the plotting function
#' attrition %>%
Expand Down
Binary file added documentation/visR.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion man/add_highlight.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/add_risktable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/align_plots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading