Variable names in Jamovi R vs. System R?

Everything related to the development of modules in jamovi
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Variable names in Jamovi R vs. System R?

Post by Mindspace »

Hi Everyone,

I'm working on a module for the RSA package and am having some difficulty getting the syntax correct.

This is the syntax for the basic model, which works fine in R Studio and in the RJ Console when using System R:

Code: Select all

RSA::RSA(outcome~predictor1*predictor2, data=data)
When trying to run the model using the RJ Console with Jamovi R, I get the following error message:
"argument predictor1 is missing, with no default"
The same error message occurs when running the analysis using the module interface, even when I replace the variable names with the coding scheme described in the tutorial:

Code: Select all

RSA::RSA(self$data$outcome~self$data$predictor1*self$data$predictor2
Am I missing something here? Is there another way to correctly designate the variable names within Jamovi R?

Or is there something else that needs to happen in order to get the RSA package to recognize the variables in Jamovi R?

Any help would be appreciated!
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

By the way, here is the full debug information in case it is useful:

Code: Select all

Debug

Error in RSAOptions$new(outcome = outcome, predictor1 = predictor1, predictor2 = predictor2, : argument "predictor1" is missing, with no default

private$.run()
eval(code, self$data, echo, self$results, figWidth = figWidth, figHeight = figHeight)
evaluate::evaluate(input = script, envir = eval.env, output_handler = handler, stop_on_error = 2)
evaluate_call(expr, parsed$src[[i]], envir = envir, enclos = enclos, debug = debug, last = i == length(out), use_try = stop_on_error != 2, keep_warning = keep_warning, keep_message = keep_message, output_handler = output_handler, include_timing = include_timing)
timing_fn(handle(ev <- withCallingHandlers(withVisible(eval(expr, envir, enclos)), warning = wHandler, error = eHandler, message = mHandler)))
handle(ev <- withCallingHandlers(withVisible(eval(expr, envir, enclos)), warning = wHandler, error = eHandler, message = mHandler))
withCallingHandlers(withVisible(eval(expr, envir, enclos)), warning = wHandler, error = eHandler, message = mHandler)
withVisible(eval(expr, envir, enclos))
eval(expr, envir, enclos)
eval(expr, envir, enclos)
RSA::RSA(outcome ~ predictor1 * predictor2, data = data)
RSAOptions$new(outcome = outcome, predictor1 = predictor1, predictor2 = predictor2, midpoint = midpoint, center = center, missing = missing, na.rm = na.rm, out.rm = out.rm, scale = scale)
.subset2(public_bind_env, "initialize")(...)
jmvcore::OptionVariable$new("predictor1", predictor1)
.subset2(public_bind_env, "initialize")(...)
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Variable names in Jamovi R vs. System R?

Post by jonathon »

hi,

first up, it looks like you've named your module RSA, and it's going to *use* the RSA package. i think you'll probably run into problems with them both having the same name. i.e. they'll always be replacing one another.

it's probably easier if you can commit the module to a git repo somewhere so we can see exactly what you're doing.

by default, jamovi modules don't support the formula interface (for the sake of exposition, i'm going to refer to your module as RSAJ, so we don't get confused wrt whether we're talking about the package or your module). so you'd run something like:

RSAJ::RSAJ(data=data, outcome=outcome, predictor1=predictor1, predictor2=predictor2)

(but it will depend on the names of the options you've defined in the .a.yaml file).

it's possible to map a formula to these values, so you can do stuff like this:

RSAJ::RSAJ(formula=outcome~predictor1+predictor2, data)

you can see how we do that here:

https://github.com/jamovi/jmv/blob/mast ... ml#L52-L62

but i wouldn't worry about that to begin with.

cheers

jonathon
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

Okay, I have setup a repository for the (very early stage) module at https://gitlab.com/MindSpace20/rsaj

I have also renamed the module as per your recommendation (as well as the analysis itself, in case that matters).

Before even getting back to the syntax issue, I am now having trouble loading the RSA package within Jamovi. In particular, I get an error when running the analysis without including RSA in the DESCRIPTION file:
Error in loadNamespace(name): there is no package called 'RSA'

Unfortunately, the module doesn't install properly when I include "Depends: RSA" or "Import: RSA" in the DESCRIPTION file, giving me the following message:
Error: package or namespace load failed for 'RSA':
.onLoad failed in loadNamespace() for 'tcltk', details:
call: NULL
error: Tcl/Tk support files were not installed
Error: package 'RSA' could not be loaded
I think this is a problem with loading tkrplot, which is a prequisite for the RSA module.

Oddly enough, when I run capabilities() in Jamovi R, it says that tcltk = TRUE, which I think means that the support files for Tcl/Tk are installed with Jamovi R, but might not be available for the RSA/tkrplot package?

Any ideas for working around this issue?
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

After digging around a bit, it turns out that this problem occurs anytime tcltk is loaded in the RJ console (regardless of my module).

I found a solution to the problem at https://stackoverflow.com/a/7075149.

Jamovi R has the tcltk package installed by default, but doesn't have the support files included in the R/Tcl folder of a regular R install.

Copying the Tcl folder from my R directory into the Jamovi R directory solved the problem.

Maybe the Tcl folder should be included in future versions of the Jamovi client?
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

Back to the main issue, I tried copying your code in the menu file, but get this error when compiling:

This only occurs when the formula terms are fed through the menu interface.
Unable to compile 'rsmap.a.yaml':
analysis additionalProperty "outcome" exists in analysis when not allowed
analysis additionalProperty "predictor1" exists in analysis when not allowed
analysis additionalProperty "predictor2" exists in analysis when not allowed
analysis.formula is not of a type(s) object
You mentioned that Jamovi modules don't support the formula interface by default. Is there a way to enable it?

The latest files are in the repository if you want to take a look: https://gitlab.com/MindSpace20/rsaj

Thanks
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

Okay, I managed to get a bare bones prototype working!

I got around the formula issue by using formula.tools::lhs and formula.tools::rhs to properly specify the formula.

Now the only remaining issue is whether the Tcl folder can be included in the Jamovi install so that tcltk-based packages work properly without manually copying the support files over.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Variable names in Jamovi R vs. System R?

Post by jonathon »

hi,

sorry for the delay in getting back to you. it's great you've been able to make progress.

the tcl situation kinda sucks for us. we need to now ship tcl/tk *only* because some dependency which isn't even being used requires it ... :/ the R dependency situation is pretty frustrating. you end up with giant dependency trees, where >95% of the packages aren't even being used. certainly no-one since the ... 90s ... has wanted to use tcltk /rant.

it might be easier to hack RSA so it doesn't use tkrplot. let me know if you want help with this.

kind regards

jonathon
Mindspace
Posts: 11
Joined: Tue Mar 03, 2020 7:31 pm

Re: Variable names in Jamovi R vs. System R?

Post by Mindspace »

As far as I can tell, RSA only uses tkrplot for the interactive demoRSA (also demoRSS, demoRSSS) functions, but it could otherwise be removed without harm.

Is this as simple as changing the dependency list for the RSA install included in the module? I tried removing references to tkrplot, tcl/tk, and demoRSA/RSS/RSSS in the DESCRIPTION and NAMESPACE files in RSAj\build\R3.6.1-win64\RSA, but it didn't stop the error. Is the dependency list embedded somewhere else? Do the dependencies have to be removed from a local copy of the RSA source prior to building the jamovi module?

Here is the RSA source, by the way: https://github.com/nicebread/RSA
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Variable names in Jamovi R vs. System R?

Post by jonathon »

let me take a look.

jonathon
Post Reply