Page 1 of 1

Do I need to use `jmvcore::toNumeric()` if we are using `permitted: - numeric`

Posted: Sun Jan 25, 2026 2:42 pm
by NourEdinDarwish
I am developing a module and looking for clarification on best practices for handling data types.

I noticed a pattern in the core `jmv` modules (for example, in the **Independent Samples T-Test** `ttestIS`).

In **`ttestIS.a.yaml`**, the variables are strictly defined with:
```yaml
permitted:
- numeric
```
This restricts the user to selecting only numeric/continuous variables in the UI.

However, in the corresponding backend code (**`ttestIS.b.R`**), there is still an explicit conversion:
```r
data[[name]] <- jmvcore::toNumeric(data[[name]])
```

**My Question:**
Is this call to `toNumeric()` redundant if the UI already enforces the type? Or does `toNumeric()` serve a critical safety role (e.g., stripping attributes or handling specific edge cases) that makes it mandatory even for ensuring "pure" numeric vectors?

Thanks!

Re: Do I need to use `jmvcore::toNumeric()` if we are using `permitted: - numeric`

Posted: Mon Jan 26, 2026 12:42 am
by jonathon
some details here (although i notice some of that page needs to be updated).

https://dev.jamovi.org/tuts0202-handling-data.html

basically we have a policy of treating nominal integer and ordinal integer variables as numeric if that's what the analysis expects ... however, nominal integer and ordinal integer variables come through to your analysis as factors ... calling as.numeric() on these factors leads to some surprising behaviour (i.e. if a factor contains 500, 1000, 2000, calling as.numeric() on it will give you 1, 2, 3), toNumeric() will achieve what you want (i.e. you'll get an integer vector with the values 500, 1000, 2000).

jonathon

Re: Do I need to use `jmvcore::toNumeric()` if we are using `permitted: - numeric`

Posted: Mon Jan 26, 2026 9:48 pm
by NourEdinDarwish
Many thanks !