Convex Optimization in R

Author

Anqi Fu and Balasubramanian Narasimhan

What is CVXR?

CVXR is an R package that provides an object-oriented modeling language for convex optimization, similar to CVX, CVXPY, YALMIP, and Convex.jl. It allows the user to formulate convex optimization problems in a natural mathematical syntax rather than the restrictive standard form required by most solvers. The user specifies an objective and set of constraints by combining constants, variables, and parameters using a library of functions with known mathematical properties. CVXR then applies signed disciplined convex programming (DCP) to verify the problem’s convexity. Once verified, the problem is converted into standard form using graph implementations and passed to a cone solver such as CLARABEL, SCS, or OSQP, or even commercial solvers, if installed.

NoteRecent Releases

CVXR 1.9.3 fixes further wrong answers, makes matrix norms agree with base R, and chooses solvers as CVXPY 1.9 does. CVXR 1.9.2 is a correctness release that also overhauls solver options and speeds up solves. CVXR 1.9.1 adds disciplined nonlinear programming (DNLP) and more. CVXR 1.8.x was a ground-up rewrite using R’s S7 class system, making the R implementation isomorphic with CVXPY. See What’s New for a version-by-version summary, the new API, and the migration guide.

Citing CVXR

CVXR is published in Fu et al. (2020) <doi:10.18637/jss.v094.i14>.

@Article{cvxr2020,
    title = {{CVXR}: An {R} Package for Disciplined Convex Optimization},
    author = {Anqi Fu and Balasubramanian Narasimhan and Stephen Boyd},
    journal = {Journal of Statistical Software},
    year = {2020},
    volume = {94},
    number = {14},
    pages = {1--34},
    doi = {10.18637/jss.v094.i14},
  }

Supported Solvers

Solver R Package LP QP SOCP SDP EXP POW MILP MIQP MISOCP
CLARABEL clarabel ✓ ✓ ✓ ✓ ✓ ✓
SCS scs ✓ ✓ ✓ ✓ ✓ ✓
MOSEK* Rmosek ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
ECOS ECOSolveR ✓ ✓ ✓ ✓
ECOS_BB ECOSolveR ✓ ✓ ✓ ✓ ✓ ✓ ✓
GUROBI* gurobi ✓ ✓ ✓ ✓ ✓ ✓
GLPK Rglpk ✓
GLPK_MI Rglpk ✓ ✓
HIGHS highs ✓ ✓ ✓
CVXOPT cccp ✓ ✓ ✓ ✓
OSQP osqp ✓ ✓
CPLEX* Rcplex ✓ ✓ ✓ ✓ ✓ ✓
PIQP piqp ✓ ✓
SCIP scip ✓ ✓ ✓ ✓ ✓ ✓
XPRESS* xpress ✓ ✓ ✓ ✓ ✓ ✓
* Commercial solver; free academic licenses are available.
QP: solvers with a quadratic-objective interface receive the objective directly; the other conic solvers solve a second-order-cone reformulation.
Without a commercial solver, mixed-integer problems can use HIGHS or GLPK_MI (MILP only), SCIP (MILP, MIQP, MISOCP) or ECOS_BB.
ECOS_BB is used only when named, as in psolve(prob, solver = "ECOS_BB").
Smooth nonlinear programs, psolve(prob, nlp = TRUE), use the separate NLP solvers Uno or IPOPT; see Using Other Solvers.

For more detail, see Using Other Solvers.

News

For the latest news, please see the Package Documentation.

CVXR continues to be developed on Github. The 1.9.3 release fixes further wrong answers, makes matrix norms agree with base R, and chooses solvers as CVXPY 1.9 does; the 1.9.2 release fixes correctness issues, overhauls solver options, and speeds up solves; the 1.9.1 release adds disciplined nonlinear programming (DNLP); and the 1.8.x series was a major release implementing a complete rewrite using R’s S7 class system, making CVXR isomorphic with CVXPY and adding support for DGP, DPP, and DQCP. More details can be found in What’s New.

Installing CVXR

CVXR is installed like any other R package from CRAN.

install.packages("CVXR")

Documentation

An introductory vignette is installed with the package and can be viewed using vignette("cvxr_intro", package = "CVXR").

A full hands-on tutorial book, Convex Optimization in R Using CVXR (prepared for useR! 2026), walks through the package step by step—from your first model through DCP, regression, portfolio optimization, and mixed-integer and nonlinear problems—with worked examples and exercises in every chapter.

A large set of examples, many ported from CVXPY, are available on this site:

Acknowledgements

We are grateful to Steven Diamond, John Miller, and Paul Kunsberg Rosenfield for their contributions to the software’s development. In particular, we are indebted to Steven Diamond for his work on CVXPY. Most of CVXR’s code, documentation, and examples were ported from the Python library.

About this site

This site is built with Quarto and is re-generated with every new release of CVXR. Many CVXPY examples have been directly converted to CVXR, serving both as tests of the package and as illustrations of its use.

References

Fu, Anqi, Balasubramanian Narasimhan, and Stephen Boyd. 2020. “CVXR: An R Package for Disciplined Convex Optimization.” Journal of Statistical Software 94 (14): 1–34. https://doi.org/10.18637/jss.v094.i14.