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

#4 add plot histogram #12

Merged

Conversation

KatrinCoboeken
Copy link
Collaborator

No description provided.

@Yuri05
Copy link
Member

Yuri05 commented Dec 8, 2023

@KatrinCoboeken 2 tests failed...

R/MappedData.R Outdated Show resolved Hide resolved
translateErrorAestethics = function() {
if (!private$aestheticExists(paste(private$direction, "min")) |
!private$aestheticExists(paste(private$direction, "max"))) {
errorType <-
intersect(names(self$mapping), c("error", "error_relativ"))
intersect(names(self$mapping), c("error", "error_relative"))
Copy link
Member

Choose a reason for hiding this comment

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

we should define constants for those strings (e.g. via the enumeration "ColumnNames" or whatsoever; compare
https://github.com/Open-Systems-Pharmacology/TLF-Library/blob/1a74ca24c2d318b5d1a6dc52f51121e1ca00c6c1/R/utilities-enums.R#L43-L48

Copy link
Member

Choose a reason for hiding this comment

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

not necessarily in this PR, but in general

Comment on lines +107 to +114
checkmate::assertDouble(
ylimits,
sorted = TRUE,
any.missing = TRUE,
len = 2,
unique = TRUE,
null.ok = TRUE
)
Copy link
Member

@Yuri05 Yuri05 Dec 8, 2023

Choose a reason for hiding this comment

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

I have seen this function several times, and all arguments (except the first one) are the same.
Consider introducing the function with just 1 argument ("checkAxisLimits(limits)" or whatsoever)

initializePlot <- function(mappedData = NULL,
setMapping = TRUE) {
# Validation
checkmate::assertClass(mappedData, classes = "MappedData", null.ok = TRUE)
Copy link
Member

@Yuri05 Yuri05 Dec 8, 2023

Choose a reason for hiding this comment

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

for many of this checks, ospsuite.utils provides validation functions, e.g.
https://www.open-systems-pharmacology.org/OSPSuite.RUtils/reference/isOfType.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was an intended omission
I want that the functions of this package are used and maybe copied and adjusted by people, with R experience but not so much ospsuite experience. So if there was a common known R function I have used that instead of an opsuite function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are other reasons to use checkmate instead of the ospsuite.utils validation functions:

  • Why write our own function, if there is already a package which does this perfectly

  • with checkmate you can adress a list of validation topics (Type, any missing, kenght,..) in one line whereas you need in ospsuite utils one line per topic.

  • Checkmate is much faster (see attached screenshot):
    Profvis_validation


# check for geomUnicodeMode
geomUnicodeMode <- getOption(
x = "ospsuite.plots.GeomPointUnicode",
Copy link
Member

Choose a reason for hiding this comment

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

please always try to define constants for things like this

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 do not think to save options as constants make sense. Options are already somethign like options.

Copy link
Member

Choose a reason for hiding this comment

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

I meant, define a constant for the string "ospsuite.plots.GeomPointUnicode" and other constant strings

@@ -178,22 +244,31 @@ buildWatermarkGrob <- function(label, x = .5, y = .5, angle = 30,
addXscale <- function(plotObject,
xscale,
xscale.args = list()) {
checkmate::assertChoice(xscale, choices = c("linear", "log"), null.ok = TRUE)
checkmate::assertChoice(xscale, choices = c("linear", "log", "discrete"), null.ok = TRUE)
Copy link
Member

Choose a reason for hiding this comment

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

Possible scales should be defined as enum, then validateEnumValue from ospuite.utils can be used

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 can define scales as enum, but

  • I prefer checkmate to validateEnumValue
  • In this case you have to be careful, for some cases (like timeprofiles) only continuous x-scales like "linear" and "log" make sense other plotTypes l(like boxwhisker) accept also discrete

Copy link
Member

Choose a reason for hiding this comment

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

you can still use the checkmate (or whatsoever other validation) with enums and check for concrete values, e.g.
checkmate::assertChoice(xscale, choices = c(xScales$linear, xScales$log), null.ok = TRUE)

plotObject = NULL,
percentiles = getOption(
x = "ospsuite.plots.Percentiles",
default = getDefaultOptions()[["ospsuite.plots.Percentiles"]]
Copy link
Member

Choose a reason for hiding this comment

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

define as constant

Copy link
Member

Choose a reason for hiding this comment

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

that was also about the string "ospsuite.plots.Percentiles"

Comment on lines 76 to 87
)




#- initialize plot
plotObject <- initializePlot(
mappedData
)


if (plotAsFrequency) {
Copy link
Member

Choose a reason for hiding this comment

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

why so many empty lines in between?

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 wil fix it

R/sysdata.rda Outdated Show resolved Hide resolved
R/utilities.R Outdated Show resolved Hide resolved
tests/testthat/Rplots.pdf Outdated Show resolved Hide resolved
DESCRIPTION Outdated
Copy link

@Felixmil Felixmil Dec 8, 2023

Choose a reason for hiding this comment

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

What is are the reasons the package Depends on ggplot2 and ggh4x?(i.e why Imports is not enough ?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Import was not enough as I used shortcuts like 'axis_minor' for ggh4x::guide_axis_minor().
I changed all such short cuts and shifted ggh4x to Import. Now it should work

#' @param mapping list of aesthetic mappings
#' @param groupAesthetics vector of aesthetics, which are used for columns mapped with aesthetic `groupby`
#' @param direction direction of plot either "x" or "y"
#' @param isObserved Flag if TRUE mappings mdv, lloq, error and error_relative are evaluated
Copy link

@Felixmil Felixmil Dec 8, 2023

Choose a reason for hiding this comment

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

I never saw Flag used in R packages or OSPS R packages to describe a boolean/logical. I can understand It but I'm not sure the users are really familiar with this naming.

@@ -1,4 +1,4 @@
# Helper for tests
# Helper for tests
getTestDataFilePath <- function(fileName) {
dataPath <- file.path(getwd(), "..", "data", fsep = .Platform$file.sep)
Copy link

@Felixmil Felixmil Dec 8, 2023

Choose a reason for hiding this comment

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

Please use testthat::test_path("data", fileName) instead, it will target tests/testthat/data/[filename].

As general rule, never use getwd() or setwd() in a package (and avoid it in general).

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 will delete the whole file. It is not needed in ospsuite.plots.
I copied it in an early version of my package from the ospsuite.ReportingEngine package.

- [ggplot2](https://cran.r-project.org/package=ggplot2/index.html)
- [ggh4x](https://cran.r-project.org/package=ggh4x/index.html)
Copy link

Choose a reason for hiding this comment

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

When installed from binary, all "Imports" and "Depends" packages will be required to be installed manually, see: https://github.com/Open-Systems-Pharmacology/OSPSuite-R#installation.

Maybe the installation part of README.Rmd from ospsuite package could be reused here.

- change Flag to boolean
- add description for installation to README.md
- delete tests/testthat/Rplots.pdf and add it to .gitingnore
- correct typos
- delete empty lines
- shift ggh4x from depends to import
- delete helperForTests
- change Flag to boolean
- add description for installation to README.md
- delete tests/testthat/Rplots.pdf and add it to .gitingnore
- correct typos
- delete empty lines
- shift ggh4x from depends to import
- delete helperForTests

replace labelsFOrpercentiles with scales::label_ordinal

Merge branch '#4_add_plot_Histogram' of https://github.com/KatrinCoboeken/OSPSuite.Plots-ztcok into #4_add_plot_Histogram

fix teastfail order of linetypes in plotratiovscov.svg  by fixing order of linetyps
@Yuri05
Copy link
Member

Yuri05 commented Dec 12, 2023

All tests are running now, yeah 🙂

From the review comments, there are some remaining issues (s. below) - but I think those can be addressed in other PRs (I would create new issues then for them).

@KatrinCoboeken So if you are not going to address any of them right now, I would approve the PR.

@KatrinCoboeken
Copy link
Collaborator Author

KatrinCoboeken commented Dec 12, 2023 via email

@Yuri05 Yuri05 merged commit 53bd60b into Open-Systems-Pharmacology:develop Dec 12, 2023
2 checks passed
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