tfmr is an R package for tabular foundation models. It provides a consistent S3 API for:
tab_pfn()tab_icl()tab_fm()
These models cover classification and regression on tabular data with mixed column types. See:
- Transformers Can Do Bayesian Inference (arXiv, 2021)
- TabPFN: A Transformer That Solves Small Tabular Classification Problems in a Second (arXiv, 2022)
- Accurate predictions on small data with a tabular foundation model (Nature, 2025)
The R interface is implemented through reticulate and follows standard
S3 methods.
You can download the package from CRAN via:
install.packages("tfmr")or you can install the development version of tfmr like so:
require(pak)
pak(c("ielbadisy/tfmr"), ask = FALSE)You’ll need a Python virtual environment to access the underlying Python libraries. After installing the R package, tfmr will install the required Python bits when you first fit a model:
> library(tfmr)
>
> predictors <- mtcars[, -1]
> outcome <- mtcars[, 1]
>
> # TabPFN example
> mod <- tab_pfn(predictors, outcome)
Downloading uv...Done!
Downloading cpython-3.12.12 (download) (15.9MiB)
Downloading cpython-3.12.12 (download)
Downloading setuptools (1.1MiB)
Downloading scikit-learn (8.2MiB)
Downloading numpy (4.9MiB)
<downloading and installing more packages>
Downloading llvmlite
Downloading torch
Installed 58 packages in 350ms
> mod
TabPFN Regression Model
Training set
i 32 data points
i 10 predictors
After loading the package:
library(tfmr)Fit a regression model via the standard x/y interface.
set.seed(364)
reg_mod <- tab_pfn(mtcars[1:25, -1], mtcars$mpg[1:25])
reg_mod
#> TabPFN Regression Model
#> Training set
#> ℹ 25 data points
#> ℹ 10 predictorsThere are also formula and recipes interfaces.
Prediction follows the usual S3 predict() method:
predict(reg_mod, mtcars[26:32, -1])
#> # A tibble: 7 × 1
#> .pred
#> <dbl>
#> 1 29.8
#> 2 25.6
#> 3 26.2
#> 4 16.5
#> 5 19.4
#> 6 14.7
#> 7 23.6tfmr uses a consistent prediction convention: a data frame is always
returned with standard column names.
For a classification model, the outcome should always be a factor
vector. For example, using these data from the modeldata package:
library(modeldata)
#>
#> Attaching package: 'modeldata'
#> The following object is masked from 'package:datasets':
#>
#> penguins
two_cls_train <- parabolic[1:400, ]
grid <- expand.grid(X1 = seq(-5.1, 5.0, length.out = 25),
X2 = seq(-5.5, 4.0, length.out = 25))
set.seed(3824)
cls_mod <- tab_pfn(class ~ ., data = two_cls_train)
predict(cls_mod, grid)
#> # A tibble: 625 × 3
#> .pred_Class1 .pred_Class2 .pred_class
#> <dbl> <dbl> <fct>
#> 1 0.988 0.0122 Class1
#> 2 0.992 0.00823 Class1
#> 3 0.993 0.00721 Class1
#> 4 0.993 0.00714 Class1
#> 5 0.991 0.00944 Class1
#> 6 0.982 0.0175 Class1
#> 7 0.965 0.0347 Class1
#> 8 0.922 0.0775 Class1
#> 9 0.799 0.201 Class1
#> 10 0.554 0.446 Class1
#> # ℹ 615 more rows| Model | Function | Backend |
|---|---|---|
| TabPFN | tab_pfn() |
PriorLabs Python package |
| TabICL | tab_icl() |
tabicl Python package |
| TabFM | tab_fm() |
Google Research tabfm Python package |
tab_icl() uses the tabicl Python backend.
icl_mod <- tab_icl(mpg ~ wt + hp, data = mtcars)
predict(icl_mod, mtcars[1:3, -1])tab_fm() uses the Google Research TabFM backend.
fm_mod <- tab_fm(mpg ~ wt + hp, data = mtcars)
predict(fm_mod, mtcars[1:3, -1])PriorLabs created the TabPFN model. Starting with version 2.5, using TabPFN requires accepting the model license and setting a token. Each model version (v2.5, v2.6, etc.) has its own license that must be accepted individually.
To get access, visit https://ux.priorlabs.ai, go to the Licenses
tab, and accept the license for each model version you intend to use.
Then set the TABPFN_TOKEN environment variable with the token from
your account. Users who already have TABPFN_TOKEN set can use TabPFN
v2 without any additional steps.
Also, the model is most effective when a GPU is available. This is a practical constraint for some workloads but is less relevant for the R interface itself.
Please note that the tfmr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.