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

Data importer #589

Merged
merged 13 commits into from
Aug 26, 2021
Merged

Data importer #589

merged 13 commits into from
Aug 26, 2021

Conversation

PavelBal
Copy link
Member

This PR implements the ImporterConfiguration and requires the Core version from this PR: Open-Systems-Pharmacology/OSPSuite.Core#1250

Importing data sets in R requires an excel file and a configuration. There are three ways to get a configuration in R:

  1. Load an existing configuration (e.g. the one created in PK-Sim or MoBi)
  2. Create a configuration from scratch
  3. Create a configuration for a file/sheet (basically what PK-Sim tries to do when starting an import process). This is not implemented yet and will be done in a separate PR.

@PavelBal
Copy link
Member Author

The failing tests should work again when the Core PR is merged.

@PavelBal
Copy link
Member Author

Each configuration has at least a time and a measurement columns, so these are created when creating an empty configuration. An error column can be added or removed manually.

@@ -0,0 +1,2 @@
createConfigurationForFile <- function(filePath) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be implemented later.

finally = {
file.remove(pkParameterResultsFilePath)
}
dataFrame <- tryCatch(
Copy link
Member Author

Choose a reason for hiding this comment

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

Run styler

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a couple of configurations created in PK-Sim for testing.


#' @field timeUnit If \code{timeUnitFromColumn} is \code{FALSE}, unit of the values in time column
#' If \code{timeUnitFromColumn} is \code{TRUE}, name of the column with units of the values in time column
timeUnit = function(value) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Time unit (the same is valid for measurement unit) - it is either a fixed unit that the user can change, or the name of the column that defines the units.

@PavelBal
Copy link
Member Author

@msevestre ready to review

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

Looks very good already . a few minor changes
Specifically, I feel that we could simplify some if the if/else by returning early and or using some of the helper methods

validateIsString(value)
# Fixed unit or from column?
if (private$.isUnitFromColumn(column)) {
# do nothing as it should be NULL
Copy link
Member

Choose a reason for hiding this comment

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

return ? So that there is no else?

Copy link
Member

Choose a reason for hiding this comment

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

return(NULL) in fact

Copy link
Member Author

Choose a reason for hiding this comment

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

Returning invisible, as usually we do not return anything when trying to set a property.

Copy link
Member

Choose a reason for hiding this comment

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

hum.. but the line above, you return(NULL)

 if (private$.isUnitFromColumn(column)) {
          return(NULL)
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

Lines 67-74: getting measurementDimension (if (missing(value)) {). If the unit of measurement is defined in a column, the dimension is NULL as it will be set on import. Return NULL because getting a value should always return something.

Lines 75-93: setting measurementDimension. In case the unit is defined in a column, specifying a dimension does not make any sense, so the action should do nothing. However, the user also does not expect the action to return anything, that' s why I use return(invisible(self)) to quit early.

if (private$.isUnitFromColumn(column)) {
# do nothing as it should be NULL
} else {
validateDimension(enc2utf8(value))
Copy link
Member

Choose a reason for hiding this comment

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

lets create a variable for this
value = enc2utf8(value) and use it everywhere. A bit too many duplicate for my likinig

Copy link
Member Author

Choose a reason for hiding this comment

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

Yepp you are right.

errorColumn = function(value) {
column <- private$.errorColumn
if (missing(value)) {
if (is.null(column)) {
Copy link
Member

Choose a reason for hiding this comment

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

if (missing(value)) {
return(NULL)
}
return(invisible(self))
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean here?isn't it somekind of weird configuration to set something but there is no column?

Copy link
Member Author

Choose a reason for hiding this comment

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

In case a configuration does not have an error column defined (this is a valid configuration), errorUnit and errorType are NULL. Trying to set errorUnit and errorType without defining an error column does not make sense, so it just does nothing (thus returning silently self), instead of throwing an error.

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

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

one last question... I like the refactoring

validateIsString(value)
# Fixed unit or from column?
if (private$.isUnitFromColumn(column)) {
# do nothing as it should be NULL
Copy link
Member

Choose a reason for hiding this comment

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

hum.. but the line above, you return(NULL)

 if (private$.isUnitFromColumn(column)) {
          return(NULL)
        }

@msevestre
Copy link
Member

Ok I am going to merge. This. The behavior with null vs invisible(self) is a bit unclear to me but these are edge cases anyways

@msevestre msevestre merged commit 89b6afa into develop Aug 26, 2021
@msevestre msevestre deleted the data-importer branch August 26, 2021 19:20
@codecov-commenter
Copy link

Codecov Report

Merging #589 (9936fd4) into develop (39c6b78) will increase coverage by 0.43%.
The diff coverage is 95.23%.

❗ Current head 9936fd4 differs from pull request most recent head 7146e84. Consider uploading reports for the commit 7146e84 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #589      +/-   ##
===========================================
+ Coverage    89.85%   90.28%   +0.43%     
===========================================
  Files           74       75       +1     
  Lines         1686     1833     +147     
===========================================
+ Hits          1515     1655     +140     
- Misses         171      178       +7     
Impacted Files Coverage Δ
R/utilities-units.R 94.11% <ø> (ø)
R/data-importer-configuration.R 95.23% <95.23%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39c6b78...7146e84. Read the comment docs.

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