Skip to content

Commit

Permalink
Format with latest version of styler (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Jul 19, 2022
1 parent 042618d commit 2828600
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 89 deletions.
10 changes: 4 additions & 6 deletions R/aaa-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@
"ggplot2::geom_linerange(",
"data = mapData,",
"mapping = aes_string(",
switch(
direction,
switch(direction,
"vertical" = "x = mapLabels$x, ymin = mapLabels$ymin, ymax = mapLabels$y,",
"horizontal" = "y = mapLabels$y, xmin = mapLabels$xmin, xmax = mapLabels$x,"
),
),
"color = mapLabels$color",
"),",
'size = .getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$size, position = 0, aesthetic = "size"),',
Expand All @@ -177,11 +176,10 @@
"ggplot2::geom_linerange(",
"data = mapData,",
"mapping = aes_string(",
switch(
direction,
switch(direction,
"vertical" = "x = mapLabels$x, ymin = mapLabels$y, ymax = mapLabels$ymax,",
"horizontal" = "y = mapLabels$y, xmin = mapLabels$x, xmax = mapLabels$xmax,"
),
),
"color = mapLabels$color",
"),",
'size = .getAestheticValues(n = 1, selectionKey = plotConfiguration$errorbars$size, position = 0, aesthetic = "size"),',
Expand Down
1 change: 0 additions & 1 deletion R/boxwhisker-get-measure.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ getBoxWhiskerMeasure <- function(data,
y = NULL,
group = NULL,
quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95)) {

# If no data mapping is input, use default
variableNames <- names(data)
y <- y %||% utils::tail(variableNames, 1)
Expand Down
1 change: 0 additions & 1 deletion R/datamapping-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ RangeDataMapping <- R6::R6Class(
size = NULL,
group = NULL,
data = NULL) {

# .smartMapping is available in utilities-mapping.R
smartMap <- .smartMapping(data)
super$initialize(x %||% smartMap$x,
Expand Down
1 change: 0 additions & 1 deletion R/datamapping-xygroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ XYGDataMapping <- R6::R6Class(
size = NULL,
group = NULL,
data = NULL) {

# .smartMapping is available in utilities-mapping.R
smartMap <- .smartMapping(data)
super$initialize(x = x %||% smartMap$x, y = y %||% smartMap$y)
Expand Down
6 changes: 3 additions & 3 deletions R/obs-vs-pred-datamapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ObsVsPredDataMapping <- R6::R6Class(
#' To map a loess smoother to the plot, use `smoother`="loess"
#' @param ... parameters inherited from `XYGDataMapping`
#' @return A new `ObsVsPredDataMapping` object
initialize = function(x = NULL,
initialize = function(x = NULL,
y = NULL,
xmin = NULL,
xmax = NULL,
Expand All @@ -35,14 +35,14 @@ ObsVsPredDataMapping <- R6::R6Class(
validateIsIncluded(smoother, c("lm", "loess"), nullAllowed = TRUE)
validateIsString(xmin, nullAllowed = TRUE)
validateIsString(xmax, nullAllowed = TRUE)
super$initialize(x=x,y=y,...)
super$initialize(x = x, y = y, ...)
self$lines <- lines
self$smoother <- smoother
# If no xmin/xmax defined, map to x to get emtpy errorbars
self$xmin <- xmin %||% self$x
self$xmax <- xmax %||% self$x
},

#' @description Check that `data` variables include map variables
#' @param data data.frame to check
#' @param metaData list containing information on `data`
Expand Down
8 changes: 4 additions & 4 deletions R/pkratio-datamapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PKRatioDataMapping <- R6::R6Class(
ymin = NULL,
#' @field ymax mapping of lower value of error bars around scatter points
ymax = NULL,

#' @description Create a new `PKRatioDataMapping` object
#' @param x Name of x variable to map
#' @param y Name of y variable to map
Expand All @@ -21,15 +21,15 @@ PKRatioDataMapping <- R6::R6Class(
#' @param lines List of ratio limits to display as horizontal lines
#' @param ... parameters inherited from `XYGDataMapping`
#' @return A new `PKRatioDataMapping` object
initialize = function(x = NULL,
y = NULL,
initialize = function(x = NULL,
y = NULL,
ymin = NULL,
ymax = NULL,
lines = DefaultDataMappingValues$pkRatio,
...) {
validateIsString(ymin, nullAllowed = TRUE)
validateIsString(ymax, nullAllowed = TRUE)
super$initialize(x=x,y=y,...)
super$initialize(x = x, y = y, ...)
self$lines <- lines
# If no ymin/ymax defined, map to y to get emtpy errorbars
self$ymin <- ymin %||% self$y
Expand Down
1 change: 0 additions & 1 deletion R/plot-boxwhisker.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ plotBoxWhisker <- function(data,
#' @return A `ggplot` object
#' @keywords internal
.addBoxWhisker <- function(data, metaData, dataMapping, plotConfiguration, plotObject) {

# Get the box plot quantiles from dataMapping
mapData <- dataMapping$getBoxWhiskerLimits(data)
# Convert the mapping into characters usable by aes_string
Expand Down
4 changes: 2 additions & 2 deletions R/plot-ddiratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' if DDI Ratio plot is drawn as residuals vs observed, instead of predicted vs observed.
#' @param foldDistance Numeric values of fold distance lines to display in log plots.
#' This argument is internally translated into `lines` field of `dataMapping`.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' In particular, line of identity corresponds to a `foldDistance` of `1`.
#' @param deltaGuest Numeric value parameter of Guest function
#' @param dataMapping
Expand Down Expand Up @@ -95,7 +95,7 @@ plotDDIRatio <- function(data,
size = .getAestheticValues(n = 1, selectionKey = plotConfiguration$lines$size, position = lineIndex, aesthetic = "size")
)


eval(.parseAddUncertaintyLayer())
eval(.parseAddScatterLayer())
# Define shapes and colors based on plotConfiguration$points properties
Expand Down
2 changes: 1 addition & 1 deletion R/plot-obs-vs-pred.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @inheritParams addScatter
#' @param foldDistance Numeric values of fold distance lines to display in log plots.
#' This argument is internally translated into `lines` field of `dataMapping`.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' In particular, line of identity corresponds to a `foldDistance` of `1`.
#' @param smoother Optional name of smoother function:
#' \itemize{
Expand Down
2 changes: 1 addition & 1 deletion R/plot-pkratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @inheritParams addScatter
#' @param foldDistance Numeric values of fold distance lines to display in log plots.
#' This argument is internally translated into `lines` field of `dataMapping`.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' In particular, line of identity corresponds to a `foldDistance` of `1`.
#' @param dataMapping
#' A `PKRatioDataMapping` object mapping `x`, `y` and aesthetic groups to their variable names of `data`.
Expand Down
14 changes: 7 additions & 7 deletions R/plotconfiguration-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ LegendConfiguration <- R6::R6Class(
private$.background <- background %||% currentTheme$background$legend

# Title properties
if(!isOfType(title, "Label")){
title <- asLabel(
text = title %||% currentTheme$background$legendTitle,
font = currentTheme$fonts$legendTitle
if (!isOfType(title, "Label")) {
title <- asLabel(
text = title %||% currentTheme$background$legendTitle,
font = currentTheme$fonts$legendTitle
)
}
private$.title <- title

private$.caption <- caption %||% data.frame()
},

Expand All @@ -54,13 +54,13 @@ LegendConfiguration <- R6::R6Class(
# Update legend title for all aesthetic properties to prevent unwanted split of legends
updateLegendTitleExpression <- parse(text = paste0(
"plotObject <- plotObject + ggplot2::guides(",
names(AestheticProperties), " = guide_legend(",
names(AestheticProperties), " = guide_legend(",
"title = private$.title$text,",
"title.theme = private$.title$createPlotFont())",
")"
))
eval(updateLegendTitleExpression)

# Update legend position and alignment
legendPosition <- .createPlotLegendPosition(private$.position)

Expand Down
1 change: 0 additions & 1 deletion R/plotconfiguration.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ PlotConfiguration <- R6::R6Class(
data = NULL,
metaData = NULL,
dataMapping = NULL) {

# Label configuration
# validation of the input is done within the creation of the object
private$.labels <- LabelConfiguration$new(
Expand Down
3 changes: 0 additions & 3 deletions R/themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ ThemeAestheticMaps <- R6::R6Class(
size = NULL,
linetype = NULL,
alpha = NULL) {

# Validate necessary input
validateIsString(color, nullAllowed = TRUE)
validateIsString(fill, nullAllowed = TRUE)
Expand Down Expand Up @@ -316,7 +315,6 @@ ThemeAestheticSelections <- R6::R6Class(
size = NULL,
linetype = NULL,
alpha = NULL) {

# Associate to each field its value
initializeExpression <- parse(text = paste0("self$", names(AestheticProperties), " <- ", names(AestheticProperties), " %||% 'first'"))
eval(initializeExpression)
Expand Down Expand Up @@ -388,7 +386,6 @@ ThemePlotConfigurations <- R6::R6Class(
plotBoxWhisker = NULL,
plotTornado = NULL,
plotHistogram = NULL) {

# Validate necessary input
atomPlotInputs <- c("addScatter", "addLine", "addRibbon", "addErrorbar")
moleculePlotInputs <- c("plotPKRatio", "plotDDIRatio", "plotTimeProfile", "plotObsVsPred", "plotBoxWhisker", "plotTornado", "plotHistogram")
Expand Down
1 change: 0 additions & 1 deletion R/timeprofile-datamapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ TimeProfileDataMapping <- R6::R6Class(
fill = NULL,
linetype = NULL,
data = NULL) {

# .smartMapping is available in utilities-mapping.R
smartMap <- .smartMapping(data)
super$initialize(
Expand Down
2 changes: 1 addition & 1 deletion R/tlf-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ setDefaultLegendPosition <- function(position) {
#' @export
setDefaultLegendTitle <- function(title) {
validateIsOfType(title, c("character", "Label"), nullAllowed = TRUE)
if(isOfType(title, "Label")){
if (isOfType(title, "Label")) {
tlfEnv$currentTheme$fonts$legendTitle <- title$font
tlfEnv$currentTheme$background$legendTitle <- title$text
return(invisible())
Expand Down
6 changes: 3 additions & 3 deletions R/utilities-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ getPiTickLabels <- function(ticks) {

#' @title .removeInfiniteValues
#' @description Censor/remove any values outside of range
#' Caution, removing infinite values can cause issues with ribbons
#' Caution, removing infinite values can cause issues with ribbons
#' which can use such infinite values for filling a range
#' @param x numeric vector of values to manipulate
#' @param range numeric vector of length two giving desired output range
#' @keywords internal
.removeInfiniteValues <- function(x, range = c(0,1)){
.removeInfiniteValues <- function(x, range = c(0, 1)) {
scales::censor(x, range, only.finite = FALSE)
}
}
4 changes: 2 additions & 2 deletions R/utilities-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ setLegendTitle <- function(plotObject,
title = NULL) {
validateIsOfType(plotObject, "ggplot")
validateIsOfType(title, c("character", "Label"), nullAllowed = TRUE)

# Clone plotConfiguration into a new plot object
# Prevents update of R6 class being spread to plotObject
newPlotObject <- plotObject
newPlotObject$plotConfiguration <- plotObject$plotConfiguration$clone(deep = TRUE)
legend <- newPlotObject$plotConfiguration$legend
if(isOfType(title, "character")){
if (isOfType(title, "character")) {
title <- asLabel(title, font = legend$title$font)
}
legend$title <- title %||% legend$title
Expand Down
36 changes: 22 additions & 14 deletions R/utilities-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
}


.binNumericCol <- function(binLimits, currentDataCol) { # function to iterate through a numeric column and find elements that fall within bin limits. Returns a logical column of the same size as the input data column.
.binNumericCol <- function(binLimits, currentDataCol) {
# function to iterate through a numeric column and find elements that fall within bin limits. Returns a logical column of the same size as the input data column.
.checkIfNotNumeric(currentDataCol, msg = "Dataframe column entries to be binned must be numeric.") # check that dataDf points to be binned are numeric
sapply(binLimits, .checkIfNotNumeric, msg = "Bin limits must be numeric") # check that all bin limits are numeric
if (!(length(binLimits) == 2)) { # check that bin limits are of length 2.
if (!(length(binLimits) == 2)) {
# check that bin limits are of length 2.
stop("Each element of bin limits list must be a vector of length 2.")
}
if (!(binLimits[2] > binLimits[1])) { # check that bin limits are in increasing order
if (!(binLimits[2] > binLimits[1])) {
# check that bin limits are in increasing order
stop("Bin limits must be increasing.")
}
dataPointsInGrp <- sapply(currentDataCol, function(x) {
Expand All @@ -25,10 +28,13 @@
.findColumnEntriesInGroups <- function(dataDf, groupingDfRow) {
groupingDataColumns <- dataDf[colnames(groupingDfRow)] # get columns from dataDf corresponding to column headings in groupingDf (excluding the last column heading in groupingDf)
logicMatrix <- matrix(rep(FALSE, nrow(dataDf) * ncol(groupingDfRow)), nrow(dataDf))
for (n in seq(1, ncol(groupingDfRow))) { # for each column of the groupingDf
if (is.list(groupingDfRow[[n]])) { # case where a list is supplied for binning
for (n in seq(1, ncol(groupingDfRow))) {
# for each column of the groupingDf
if (is.list(groupingDfRow[[n]])) {
# case where a list is supplied for binning
logicMatrix[, n] <- .binNumericCol(groupingDfRow[[n]][[1]], groupingDataColumns[[n]]) # check if each column entry lies within bin limits. If yes, return TRUE for that entry, else FALSE.
} else { # case where there is no binning, only matching between caption dataframe entries and dataDf column entries
} else {
# case where there is no binning, only matching between caption dataframe entries and dataDf column entries
logicMatrix[, n] <- sapply(groupingDataColumns[[n]], function(x) {
return(x == groupingDfRow[[n]])
}) # check if each column entry matches groupingDf element. If yes, return TRUE for that entry, else FALSE.
Expand All @@ -45,10 +51,13 @@
stopifnot(ncol(groupingDf) > 1)
vecIndxGroupingDfRows <- seq(1, nrow(groupingDf)) # vector of factor levels associated with each caption
groupingFactorColumn <- rep(0, nrow(dataDf)) # vector that is to be populated with factor levels that determine caption
for (k in vecIndxGroupingDfRows) { # for each caption
for (k in vecIndxGroupingDfRows) {
# for each caption
logicMatrix <- .findColumnEntriesInGroups(dataDf, groupingDf[k, -ncol(groupingDf), drop = FALSE]) # call function to test if each column entry falls within the grouping
for (m in seq(1, nrow(dataDf))) { # for each row of dataDf
if (all(logicMatrix[m, ])) { # if entire dataDf row matches groupingDf row
for (m in seq(1, nrow(dataDf))) {
# for each row of dataDf
if (all(logicMatrix[m, ])) {
# if entire dataDf row matches groupingDf row
groupingFactorColumn[m] <- vecIndxGroupingDfRows[k] # set factor level in groupingFactorColumn to k
}
}
Expand Down Expand Up @@ -89,7 +98,6 @@
#' # Get captions separating variables witha space (character " ")
#' getDefaultCaptions(data, metaData, sep = " ")
getDefaultCaptions <- function(data, metaData, variableList = colnames(data), sep = "-") {

# Check that the grouping is in the list of data variables
stopifnot(variableList %in% colnames(data))

Expand Down Expand Up @@ -274,7 +282,7 @@ DefaultDataMappingValues <- list(
#' Get list of values to provide to `lines` argument of `dataMapping` objects.
#' The `lines` are internally used as argument of `geom_hline` and `geom_abline` from `ggplot2`
#' @param foldDistance Numeric values
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' __Caution__: this argument is meant for log scaled plots and since fold distance is a ratio it is expected positive.
#' In particular, line of identity corresponds to a `foldDistance` of `1`.
#' @return A list of numeric values
#' @export
Expand Down Expand Up @@ -317,9 +325,9 @@ getLinesFromFoldDistance <- function(foldDistance) {
}

.getAggregatedData <- function(data,
xParameterName,
yParameterName,
xParameterBreaks = NULL) {
xParameterName,
yParameterName,
xParameterBreaks = NULL) {
xParameterBreaks <- xParameterBreaks %||% tlfEnv$defaultAggregation$bins
xParameterBins <- cut(data[, xParameterName], breaks = xParameterBreaks)

Expand Down
2 changes: 0 additions & 2 deletions inst/theme-maker/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ ui <- fluidPage(

#---------- Server ----------#
server <- function(input, output) {

#---------- Interactive way of updating aesthetic map element ----------#
getColorMapValue <- reactive({
jsonTheme$aestheticMaps$color[input$colorMapIndex]
Expand Down Expand Up @@ -296,7 +295,6 @@ server <- function(input, output) {
})

output$samplePlot <- renderPlot({

# Reactive function that update theme object
updateTheme()
plotConfiguration <- PlotConfiguration$new(title = "title", subtitle = "subtitle", xlabel = "xlabel", ylabel = "ylabel", caption = "caption")
Expand Down
Loading

0 comments on commit 2828600

Please sign in to comment.