-
Notifications
You must be signed in to change notification settings - Fork 13
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
Fix dataSetToDataFrame #606
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,38 +55,64 @@ saveDataSetToPKML <- function(dataSet, filePath) { | |
rClr::clrCall(dataRepositoryTask, "SaveDataRepository", dataSet$dataRepository$ref, filePath) | ||
} | ||
|
||
#' Converts a list of DataSet objects to a data.frame | ||
#' Converts a list of `DataSet` objects to a data.frame | ||
#' | ||
#' @param dataSets A list of DataSet objects or a single DataSet | ||
#' @param dataSets A list of `DataSet` objects or a single `DataSet` | ||
#' | ||
#' @return DataSet objects as data.frame with columns name, xValue, yValue, yErrorValues, | ||
#' xDimension, xUnit, yDimension, yUnit, yErrorType, yErrorUnit, yMolWeight | ||
#' @return DataSet objects as data.frame with columns name, xValues, yValues, yErrorValues, | ||
#' xDimension, xUnit, yDimension, yUnit, yErrorType, yErrorUnit, molWeight, lloq, | ||
#' and a column for each meta data that is present in any `DataSet` | ||
#' @export | ||
dataSetToDataFrame <- function(dataSets) { | ||
dataSets <- c(dataSets) | ||
validateIsOfType(dataSets, DataSet) | ||
|
||
name <- unlist(mapply(.makeDataFrameColumn, dataSets, "name")) | ||
xUnit <- unlist(mapply(.makeDataFrameColumn, dataSets, "xUnit")) | ||
yUnit <- unlist(mapply(.makeDataFrameColumn, dataSets, "yUnit")) | ||
yErrorUnit <- as.character(unlist(mapply(.makeDataFrameColumn, dataSets, "yErrorUnit"))) | ||
xDimension <- unlist(mapply(.makeDataFrameColumn, dataSets, "xDimension")) | ||
yDimension <- unlist(mapply(.makeDataFrameColumn, dataSets, "yDimension")) | ||
yErrorType <- as.character(unlist(mapply(.makeDataFrameColumn, dataSets, "yErrorType"))) | ||
yMolWeight <- unlist(mapply(.makeDataFrameColumn, dataSets, "molWeight")) | ||
xValue <- unlist(mapply(.makeDataFrameColumn, dataSets, "xValues")) | ||
yValue <- unlist(mapply(.makeDataFrameColumn, dataSets, "yValues")) | ||
yErrorValues <- unlist(mapply(.makeDataFrameColumn, dataSets, "yErrorValues")) | ||
name <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "name") | ||
}), use.names = FALSE) | ||
xUnit <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "xUnit") | ||
}), use.names = FALSE) | ||
yUnit <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yUnit") | ||
}), use.names = FALSE) | ||
yErrorUnit <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yErrorUnit") | ||
}), use.names = FALSE) | ||
xDimension <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "xDimension") | ||
}), use.names = FALSE) | ||
yDimension <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yDimension") | ||
}), use.names = FALSE) | ||
yErrorType <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yErrorType") | ||
}), use.names = FALSE) | ||
molWeight <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "molWeight") | ||
}), use.names = FALSE) | ||
xValues <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "xValues") | ||
}), use.names = FALSE) | ||
yValues <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yValues") | ||
}), use.names = FALSE) | ||
yErrorValues <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "yErrorValues") | ||
}), use.names = FALSE) | ||
lloq <- unlist(lapply(dataSets, function(x) { | ||
.makeDataFrameColumn(x, "LLOQ") | ||
}), use.names = FALSE) | ||
|
||
df <- data.frame( | ||
name, xValue, yValue, yErrorValues, xDimension, xUnit, yDimension, | ||
yUnit, yErrorType, yErrorUnit, yMolWeight | ||
name, xValues, yValues, yErrorValues, xDimension, xUnit, yDimension, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed column names (using plural) and added a LLOQ column. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if feels like you could write a method
or sthg like this |
||
yUnit, yErrorType, yErrorUnit, molWeight, lloq | ||
) | ||
|
||
# get all names of meta data entries from all data sets | ||
metaDataNames <- unique(unlist(sapply(dataSets, function(dataSets) { | ||
return(names(dataSets[["metaData"]])) | ||
}))) | ||
metaDataNames <- unique(unlist(lapply(dataSets, function(dataSets) { | ||
names(dataSets[["metaData"]]) | ||
}), use.names = FALSE)) | ||
# add one column for each one | ||
for (name in metaDataNames) { | ||
col <- unlist(lapply(dataSets, .makeDataFrameColumn, "metaData", metaDataName = name)) | ||
|
@@ -127,11 +153,11 @@ loadDataSetsFromExcel <- function(xlsFilePath, importerConfiguration, importAllS | |
dataImporterTask <- getNetTask("DataImporterTask") | ||
rClr::clrSet(dataImporterTask, "IgnoreSheetNamesAtImport", importAllSheets) | ||
dataRepositories <- rClr::clrCall(dataImporterTask, "ImportExcelFromConfiguration", importerConfiguration$ref, xlsFilePath) | ||
dataSets <- lapply(dataRepositories, function(x){ | ||
dataSets <- lapply(dataRepositories, function(x) { | ||
repository <- DataRepository$new(x) | ||
DataSet$new(repository) | ||
}) | ||
names(dataSets) <- lapply(dataSets, function(x){ | ||
names(dataSets) <- lapply(dataSets, function(x) { | ||
x$name | ||
}) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
mapply and sapply and so produce weird results sometimes (in case of data sets loaded from excel the output was a matrix, in the case of manually created data sets it was a vector...),
lapply
is the only function that always will return a list, so lets use it where possible.Adding
use.naames = FALSE
tounlist
speeds up the whole thing and should be used when we do not need a named list.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.
@hannaei FYI