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

Use preloadData stuff #314

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions R/descriptives.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This is a temporary fix
# TODO: remove it when R will solve this problem!
gettextf <- function(fmt, ..., domain = NULL) {
return(sprintf(gettext(fmt, domain = domain), ...))
}

DescriptivesInternal <- function(jaspResults, dataset, options) {
variables <- unlist(options$variables)
splitName <- options$splitBy
Expand All @@ -31,8 +25,16 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
temp <- .descriptivesReadData(options, variables, splitName)
dataset <- temp[["dataset"]]
dataset.factors <- temp[["dataset.factors"]]
isNominalText <- temp[["isNominalText"]]
}
else
{
dataset.factors <- .readDataSetToEnd(columns.as.factor = c(variables, splitName))
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but wouldn't it make more sense to assume that if preloadData = TRUE then .readDataSetToEnd is a no-op? This could also be

Suggested change
dataset.factors <- .readDataSetToEnd(columns.as.factor = c(variables, splitName))
dataset.factors <- dataset
for (var in c(variables, splitName))
dataset.factors[[var]] <- as.factor(dataset.factors[[var]])

although I guess there is no guarantee that this is exactly the same as if you'd read the variables as factor directly (e.g., read facGender as numeric -> all NA -> as.factor -> all NA vs. read facGender as factor -> actual data). Hmm this really shows descriptives needs another rewrite...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, if you disable preloading in Description.qml it will go back to the old behaviour anyway

}

allMissing <- \(x) all(is.na(x))
missingAllAsNumeric <- vapply(dataset, allMissing, FUN.VALUE = logical(1L))
missingAllAsIs <- vapply(dataset.factors, allMissing, FUN.VALUE = logical(1L))
isNominalText <- missingAllAsNumeric & !missingAllAsIs[names(missingAllAsNumeric)]

if (makeSplit && length(variables) > 0) {
splitFactor <- dataset[[splitName]]
Expand Down Expand Up @@ -387,11 +389,8 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
dataset.factors <- dataset

allMissing <- \(x) all(is.na(x))
missingAllAsNumeric <- vapply(dataset, allMissing, FUN.VALUE = logical(1L))
missingAllAsIs <- vapply(dataset.factors, allMissing, FUN.VALUE = logical(1L))
isNominalText <- missingAllAsNumeric & !missingAllAsIs[names(missingAllAsNumeric)]

return(list(dataset = dataset, dataset.factors = dataset.factors, isNominalText = isNominalText))
return(list(dataset = dataset, dataset.factors = dataset.factors))
}

.descriptivesDescriptivesTable <- function(dataset, dataset.factors, isNominalText, options, jaspResults, numberMissingSplitBy = 0) {
Expand Down
6 changes: 4 additions & 2 deletions inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Description
license : "GPL (>= 2)"
icon : "analysis-descriptives.svg"
hasWrappers : true
preloadData : false

Analysis
{
title: qsTr("Descriptive Statistics")
func: "Descriptives"
title: qsTr("Descriptive Statistics")
func: "Descriptives"
preloadData : true
}

Analysis
Expand Down
Loading