-
Notifications
You must be signed in to change notification settings - Fork 12
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
Data importer #589
Conversation
The failing tests should work again when the Core PR is merged. |
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) { |
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.
Will be implemented later.
R/utilities-pk-analysis.R
Outdated
finally = { | ||
file.remove(pkParameterResultsFilePath) | ||
} | ||
dataFrame <- tryCatch( |
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.
Run styler
@@ -0,0 +1,30 @@ | |||
<?xml version="1.0" encoding="utf-8"?> |
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.
Added a couple of configurations created in PK-Sim for testing.
R/data-importer-configuration.R
Outdated
|
||
#' @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) { |
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.
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.
@msevestre ready to review |
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.
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
R/data-importer-configuration.R
Outdated
validateIsString(value) | ||
# Fixed unit or from column? | ||
if (private$.isUnitFromColumn(column)) { | ||
# do nothing as it should be NULL |
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.
return ? So that there is no else?
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.
return(NULL) in fact
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.
Returning invisible, as usually we do not return anything when trying to set a property.
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.
hum.. but the line above, you return(NULL)
if (private$.isUnitFromColumn(column)) {
return(NULL)
}
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.
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.
R/data-importer-configuration.R
Outdated
if (private$.isUnitFromColumn(column)) { | ||
# do nothing as it should be NULL | ||
} else { | ||
validateDimension(enc2utf8(value)) |
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.
lets create a variable for this
value = enc2utf8(value) and use it everywhere. A bit too many duplicate for my likinig
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.
Yepp you are right.
R/data-importer-configuration.R
Outdated
errorColumn = function(value) { | ||
column <- private$.errorColumn | ||
if (missing(value)) { | ||
if (is.null(column)) { |
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.
a cool method to simplify all those if
https://github.com/Open-Systems-Pharmacology/OSPSuite-R/blob/develop/R/utilities.R#L44
R/data-importer-configuration.R
Outdated
if (missing(value)) { | ||
return(NULL) | ||
} | ||
return(invisible(self)) |
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.
What does this mean here?isn't it somekind of weird configuration to set something but there is no column?
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.
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.
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.
one last question... I like the refactoring
R/data-importer-configuration.R
Outdated
validateIsString(value) | ||
# Fixed unit or from column? | ||
if (private$.isUnitFromColumn(column)) { | ||
# do nothing as it should be NULL |
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.
hum.. but the line above, you return(NULL)
if (private$.isUnitFromColumn(column)) {
return(NULL)
}
…ure xml files are valid files
3e9808b
to
9936fd4
Compare
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 |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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: