Hello !
Is there any possibility to create a module for Jamovi that can automatically create new columns , it might create 1 or 3 or 7 it depends ...
Is it possible ?
Thank you.
Module that can add new columns
Re: Module that can add new columns
Hi,
yes it is, although it's not extremely well documented.
what does the number of columns depend on? it's easy if there's a simple formula for it, i.e. there are as many columns as there are variables specified by the user ... but if the number of columns is more complex, i.e. determined by an analysis, and not known in advance, then that is a bit trickier.
what's your situation?
jonathon
yes it is, although it's not extremely well documented.
what does the number of columns depend on? it's easy if there's a simple formula for it, i.e. there are as many columns as there are variables specified by the user ... but if the number of columns is more complex, i.e. determined by an analysis, and not known in advance, then that is a bit trickier.
what's your situation?
jonathon
Re: Module that can add new columns
Hi Jonathon,
Thanks for your quick response!
I’m currently working on a module that can split a variable. In certain cases, I have a variable with values like "a,b,c", and I want to automatically split this into three new columns. Each new column should be named based on the original column name followed by the value (e.g., "original_name_a"). The values in these new columns should be either 1 or 0, depending on whether the value is present.
To keep things simple, could you provide a basic code snippet (for b.R) that will create just one new column for testing purposes? I tried implementing it myself, but it didn’t work.
Thanks for your quick response!
I’m currently working on a module that can split a variable. In certain cases, I have a variable with values like "a,b,c", and I want to automatically split this into three new columns. Each new column should be named based on the original column name followed by the value (e.g., "original_name_a"). The values in these new columns should be either 1 or 0, depending on whether the value is present.
To keep things simple, could you provide a basic code snippet (for b.R) that will create just one new column for testing purposes? I tried implementing it myself, but it didn’t work.
Re: Module that can add new columns
ah, righto ... it sounds a lot like you're implementing dummy coding 
this is the more difficult one to implement ... but it's not too bad.
step 1. add an output results to your .r.yaml, something like:
https://github.com/jamovi/jmv/blob/22c9 ... #L201-L210
step 2. add a matching option to your .a.yaml to activate it:
https://github.com/jamovi/jmv/blob/22c9 ... #L169-L171
step 3.
setup the columns:
keys, titles, descriptions, measureTypes should all be character vectors of the same length (as many columns as you want). i.e.
step 4. populate the data:
something like:
...
here's an example from the PCA.
https://github.com/jamovi/jmv/blob/22c9 ... #L440-L474
come back to us if you get stuck.

this is the more difficult one to implement ... but it's not too bad.
step 1. add an output results to your .r.yaml, something like:
Code: Select all
- name: factorScoresOV
title: Factor scores
type: Output
initInRun: true
step 2. add a matching option to your .a.yaml to activate it:
Code: Select all
- name: factorScoresOV
title: Component scores
type: Output
step 3.
setup the columns:
Code: Select all
self$results$factorScoresOV$set(
keys=keys,
titles=titles,
descriptions=descriptions,
measureTypes=measureTypes
)
Code: Select all
self$results$factorScoresOV$set(
keys=c('1', '2'),
titles=c('column 1', 'column 2'),
descriptions=c('this column represents', '... and this column represents'),
measureTypes=c('continuous', 'continuous')
)
something like:
Code: Select all
for (i in 1:self$nFactors) {
scores <- as.numeric(self$scores[, i])
self$results$factorScoresOV$setValues(index=i, scores)
}
here's an example from the PCA.
https://github.com/jamovi/jmv/blob/22c9 ... #L440-L474
come back to us if you get stuck.
Re: Module that can add new columns
Thank you, will give it a try Tomorrow and tell you the results
Re: Module that can add new columns
Thank Jonathon for your guidance.
I've finalized the module for splitting combined data columns into separate columns. I have a question regarding distribution—how can I make this module accessible to everyone?
Looking forward to your advice.
I've finalized the module for splitting combined data columns into separate columns. I have a question regarding distribution—how can I make this module accessible to everyone?
Looking forward to your advice.
Re: Module that can add new columns
if you place it under an open-source license, list in a public git repo (i.e. github), we can look at listing it in the jamovi library.
if that's where you want to go, submit it, we'll take a look, make some suggestions, and after a bit of back and forth we list it in the library.
jonathon
if that's where you want to go, submit it, we'll take a look, make some suggestions, and after a bit of back and forth we list it in the library.
jonathon