Hello,
I am just starting to develop modules for Jamovi and have successfully implemented a few so far. However, I am facing an issue with one specific module, and I would greatly appreciate some assistance.
The module I am working on is for data imputation using the missRanger package.
Everything seems to be working fine, but I keep receiving the message:
"This analysis has terminated, likely due to hitting a resource limit."
Below are my code files for your review.
Would anyone have any ideas on what might be causing this issue?
.a.yaml File:
name: missRangerImputation
title: MissRanger Imputation
menuGroup: BSS
menuSubgroup: Data handling
menuSubtitle: Under development...
version: '0.0.1'
jas: '1.2'
options:
- name: data
type: Data
- name: vars
title: Variables to Impute
type: Variables
suggested:
- continuous
- nominal
- ordinal
required: true
permitted:
- numeric
- factor
- name: maxiter
title: Maximum Iterations
type: Integer
default: 10
min: 1
max: 100
- name: num_trees
title: Number of Trees
type: Integer
default: 100
min: 1
max: 500
- name: pmm_k
title: Number of Donors for PMM
type: Integer
default: 5
min: 1
max: 20
- name: saveData
title: Add Imputed Values as New Column
type: Bool
default: false
.r.yaml File:
name: missRangerImputation
title: MissRanger Imputation Results
jrs: '1.1'
items:
- name: text
title: MissRanger Imputation Summary
type: Preformatted
- name: missingSummary
title: Missing Data Summary
type: Table
rows: 0
columns:
- name: variable
title: Variable
type: text
- name: total_missing
title: Missing Values
type: integer
- name: percent_missing
title: Missing (%)
type: number
format: '%.2f'
- name: imputedDataTable
title: Imputed Data Summary
type: Table
rows: 0
columns:
- name: variable
title: Variable
type: text
- name: original_value
title: Original Value
type: text
- name: imputed_value
title: Imputed Value
type: text
- name: row_number
title: Row
type: integer
.b.R File:
missRangerImputationClass <- if (requireNamespace('R6', quietly=TRUE)) R6::R6Class(
"missRangerImputationClass",
inherit = missRangerImputationBase,
public = list(
initialize = function(...) {
super$initialize(...)
},
run = function() {
# Checks if variables are selected
if (length(self$options$vars) == 0) {
self$results$text$setContent("Please select at least one variable for imputation.")
return()
}
# Checks if the 'missRanger' package is available
if (!requireNamespace("missRanger", quietly = TRUE)) {
stop("The 'missRanger' package is not installed.")
}
# Loads the package
library(missRanger)
# Prepares the dataset
df <- self$data
selected_vars <- self$options$vars
# Creates missing data summary
for (var in selected_vars) {
n_missing <- sum(is.na(df[[var]]))
pct_missing <- (n_missing / nrow(df)) * 100
self$results$missingSummary$addRow(list(
variable = var,
total_missing = n_missing,
percent_missing = pct_missing
))
}
# If no missing data, stops execution
missing_summary_df <- self$results$missingSummary$asDF()
if (nrow(missing_summary_df) == 0 || sum(missing_summary_df$total_missing) == 0) {
self$results$text$setContent("None of the selected variables have missing values for imputation.")
return()
}
# Performs imputation
imputed_data <- tryCatch({
message("Starting imputation...")
missRanger(
data = df,
maxiter = self$options$maxiter,
num.trees = self$options$num_trees,
pmm.k = self$options$pmm_k,
verbose = TRUE
)
}, error = function(e) {
self$results$text$setContent(paste("Error during imputation:", e$message))
return(NULL)
})
if (is.null(imputed_data)) return()
# Adds imputed data to results table
for (var in selected_vars) {
na_indices <- which(is.na(df[[var]]))
if (length(na_indices) > 0) {
for (idx in na_indices) {
original_val <- df[[var]][idx]
imputed_val <- imputed_data[[var]][idx]
self$results$imputedDataTable$addRow(list(
variable = var,
original_value = "NA",
imputed_value = as.character(imputed_val),
row_number = idx
))
}
}
}
# Updates text summary
total_imputations <- nrow(self$results$imputedDataTable$asDF())
summary_text <- sprintf(
"Imputation completed!\n\nDetails:\n- Number of trees: %d\n- Max iterations: %d\n- PMM donors: %d\n- Imputed variables: %s\n- Total imputations: %d",
self$options$num_trees,
self$options$maxiter,
self$options$pmm_k,
paste(selected_vars, collapse = ", "),
total_imputations
)
self$results$text$setContent(summary_text)
# Adds imputed data as new columns if requested
if (self$options$saveData) {
for (var in selected_vars) {
new_col_name <- paste0(var, "_imputed")
self$data[[new_col_name]] <- imputed_data[[var]]
}
}
}
)
)
Thanks in advance for any suggestions!
Help with Implementing missRanger Imputation Module - Resource Limit Error
Re: Help with Implementing missRanger Imputation Module - Resource Limit Error
hi,
the error "This analysis has terminated, likely due to hitting a resource limit." means that the R process running the analysis has crashed.
you could try running jamovi at the terminal, and see if there's additional error messages.
under macOS this would be running
/Applications/jamovi.app/Contents/MacOS/jamovi
under windows you'll find "jamovi debug" in the start menu, and you can start jamovi with
jamovi --debug2
(the positions of the dashes and spaces isn't negotiable).
when run like this under windows, you'll see some additional windows are created (one for each engine process), and when an engine crashes, error ouput is typically written to one of the windows... but this is where it gets tricky, because after the crash, the window disappears before you can really read what it says. i normally end up running screen recording software, and then step through the recording frame by frame so i can read the error text. bit of a pita.
jonathon
the error "This analysis has terminated, likely due to hitting a resource limit." means that the R process running the analysis has crashed.
you could try running jamovi at the terminal, and see if there's additional error messages.
under macOS this would be running
/Applications/jamovi.app/Contents/MacOS/jamovi
under windows you'll find "jamovi debug" in the start menu, and you can start jamovi with
jamovi --debug2
(the positions of the dashes and spaces isn't negotiable).
when run like this under windows, you'll see some additional windows are created (one for each engine process), and when an engine crashes, error ouput is typically written to one of the windows... but this is where it gets tricky, because after the crash, the window disappears before you can really read what it says. i normally end up running screen recording software, and then step through the recording frame by frame so i can read the error text. bit of a pita.
jonathon
Re: Help with Implementing missRanger Imputation Module - Resource Limit Error
Hello,
Thank you so much for the quick response and the helpful information.
I followed your instructions, and I encountered the following error:
Error in (function ( ) : unused argument (noThrow = TRUE)
terminate called after throwing an instance of 'Rcpp::LongjumpException'
(image URL) https://drive.google.com/file/d/1inFGt- ... drive_link
Another error also appeared, but I am not sure if it is significant. Regardless, I have attached an image below for your review.
Engine process terminated Exit code: 3221225786
(image URL) https://drive.google.com/file/d/1KdKY3c ... drive_link
Thank you again for your help!
Rafael.
Thank you so much for the quick response and the helpful information.
I followed your instructions, and I encountered the following error:
Error in (function ( ) : unused argument (noThrow = TRUE)
terminate called after throwing an instance of 'Rcpp::LongjumpException'
(image URL) https://drive.google.com/file/d/1inFGt- ... drive_link
Another error also appeared, but I am not sure if it is significant. Regardless, I have attached an image below for your review.
Engine process terminated Exit code: 3221225786
(image URL) https://drive.google.com/file/d/1KdKY3c ... drive_link
Thank you again for your help!
Rafael.
Re: Help with Implementing missRanger Imputation Module - Resource Limit Error
ah, i think the issue is because you have a function called run() in your module ... this is clobbering the run() method in the analysis class. i think you want to call it .run() rather than run()
cheers
jonathon
cheers
jonathon
Re: Help with Implementing missRanger Imputation Module - Resource Limit Error
Thank you so much! I applied your suggested fix, and the error disappeared.
However, the table is not populating as expected, so I realize I still need to refine my code further.
I appreciate your help and guidance—thank you again!
Regards,
Rafael.
However, the table is not populating as expected, so I realize I still need to refine my code further.
I appreciate your help and guidance—thank you again!
Regards,
Rafael.