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

Everything related to the development of modules in jamovi
Post Reply
NourEdinDarwish
Posts: 3
Joined: Fri Jan 23, 2026 9:14 pm

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

Post 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!
User avatar
jonathon
Posts: 2934
Joined: Fri Jan 27, 2017 10:04 am

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

Post 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
Post Reply