Learn R Programming

CVXR

CVXR provides an object-oriented modeling language for convex optimization, similar to CVXPY, CVX, YALMIP, and Convex.jl. It allows you to formulate convex optimization problems in natural mathematical syntax rather than the restrictive standard form required by most solvers. You specify an objective and a 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 conic form and passed to an appropriate backend solver.

This version is a ground-up rewrite built on the S7 object system, designed to mirror CVXPY 1.9.1 closely. It is ~4–5x faster than the previous S4-based release, ships with 15 solvers (4 built-in), and supports DCP, DGP, DQCP, disciplined nonlinear programming (DNLP), complex variables, mixed-integer programming, warm-starting, and a derivative / sensitivity-analysis API.

For tutorials, worked examples, and the full story, visit the CVXR website.

Installation

Install the released version from CRAN:

install.packages("CVXR")

Or install the development version from GitHub:

# install.packages("pak")
pak::pak("cvxgrp/CVXR")

Quick example

library(CVXR)

# Data
set.seed(42)
n <- 50; p <- 10
X <- matrix(rnorm(n * p), n, p)
beta_true <- c(rep(1, 5), rep(0, 5))
y <- X %*% beta_true + rnorm(n, sd = 0.5)

# Problem
beta <- Variable(p)
objective <- Minimize(sum_squares(y - X %*% beta) + 0.1 * p_norm(beta, 1))
prob <- Problem(objective)

# Solve (Clarabel is the default solver)
result <- psolve(prob)
result                          # optimal value
estimated <- value(beta)        # coefficient estimates

Documentation

If you use CVXR in your work, please cite the paper above (citation("CVXR")).

License

Apache License 2.0

Copy Link

Version

Install

install.packages('CVXR')

Monthly Downloads

17,122

Version

1.9.1

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

June 9th, 2026

Functions in CVXR (1.9.1)

FiniteSet

FiniteSet Constraint
Variable

Create an Optimization Variable
Not

Logical NOT
NonPos

Create a Non-Positive Constraint
CallbackParam

Callback Parameter
Constant

Create a Constant Expression
And

Logical AND
DiagVec

Vector to Diagonal Matrix
Equality

Create an Equality Constraint
Parameter

Create a Parameter
SizeMetrics

Problem Size Metrics
PowCone3D

Create a 3D Power Cone Constraint
PowConeND

Create an N-Dimensional Power Cone Constraint
PartialProblem

Partial optimization of a Problem
SolverError

Solver Error condition
CVXR-package

CVXR: Disciplined Convex Optimization
Inequality

Create an Inequality Constraint
Maximize

Create a Maximization Objective
Minimize

Create a Minimization Objective
NonNeg

Create a Non-Negative Constraint
backward

Compute the gradient of a solution with respect to Parameters
Problem

Create an Optimization Problem
PSD

Create a Positive Semidefinite Constraint
SOC

Create a Second-Order Cone Constraint
Or

Logical OR
atoms

Get the Atoms in an Expression
Xor

Logical XOR
as_cvxr_expr

Convert a value to a CVXR Expression
cummax_expr

Cumulative maximum along an axis
cvxr_mean

Mean of an expression
convolve

1D discrete convolution (numpy-style)
cvxr_std

Standard deviation of an expression
cone_sizes

Get the Sizes of Individual Cones
broadcast_args

Broadcast two expressions for binary operations
conj_expr

Elementwise Complex Conjugate
atom_domain

Get Atom-Specific Domain Constraints
canonical_form

Get the Canonical Form
.constant_grad

Gradient of a Constant Expression
bmat

Construct a Block Matrix
.error_grad

Error Gradient (None for every variable)
Zero

Create a Zero Constraint
cvxr_norm

Compute a norm of an expression
get_data

Get Atom-Specific Data
get_bounds

Lower/Upper Bounds of a Leaf
constr_size

Get the Total Size of a Constraint
constants

Get the Constants in an Expression
cvxr_diff

Compute kth Order Differences of an Expression
cvar

Conditional Value at Risk (CVaR)
expr_copy

Shallow Copy of an Expression Tree Node
apply_param_jac

Adjoint of the parameter -> (c, d, A, b) tensor map
available_solvers

List available solvers
conv

1D discrete convolution
constraints

Get Problem Constraints (read-only)
cvxr_outer

Outer product of two vectors
gmatmul

Geometric matrix multiplication A diamond X
get_problem_data

Get Problem Data for a Solver (deprecated)
expr_name

Get the Name of an Expression
delta

Access the perturbation delta of a Variable or Parameter
derivative

Apply the derivative of the solution map to perturbations
cdiac

Global Monthly and Annual Temperature Anomalies (degrees C), 1850-2015 (Relative to the 1961-1990 Mean) (May 2016)
canonicalize

Canonicalize an Expression
imag_expr

Extract Imaginary Part of Expression
%>>%

Positive Semidefinite Constraint Operator
inv_prod

Reciprocal of product of entries
iff

Logical Biconditional
%<<%

Negative Semidefinite Constraint Operator
inv_pos

Inverse position: \(x^{-1}\) (for x > 0)
has_quadratic_term

Check if Expression Has a Quadratic Term
dspop

Direct Standardization: Population
dpp_scope_active

Check if DPP Scope is Active
is_constant

Check if an Expression is Constant
is_incr

Check if Atom is Increasing in an Argument
is_convex

Check if an Expression is Convex
is_matrix

Is the Expression a Matrix?
is_linearizable_concave

Check if an Expression is Linearizable-Concave
is_lp

Check if a Problem is a Linear Program
is_pwl

Check if Expression is Piecewise Linear
hstack

Horizontal concatenation of expressions
intf_is_skew_symmetric

Check if a matrix is skew-symmetric (A + A^T == 0)
floor_expr

Elementwise Floor
installed_solvers

List installed solvers
huber

Create a Huber loss atom
id

Get Expression ID
format_labeled

Pretty-print an expression with labels substituted
intf_convert

Convert a value to a numeric matrix or sparse matrix
is_qp

Check if a Problem is a Quadratic Program
lambda_max

Maximum eigenvalue
lambda_min

Minimum eigenvalue
cumsum_axis

Cumulative sum along an axis
curvature

Get Expression Curvature
condition_number

Condition number of a PSD matrix
ceil_expr

Elementwise Ceiling
cvxr_var

Variance of an expression
domain

Get the Domain Constraints of an Expression
dual_value

Get the Dual Value of a Constraint
is_dcp

Check if an Expression is DCP-Compliant
is_hermitian

Check if Expression is Hermitian
.column_grad

Per-column Subgradient for AxisAtoms (private)
is_decr

Check if Atom is Decreasing in an Argument
intf_is_sparse

Check if a value is a sparse matrix
intf_sign

Determine the sign of a numeric value
dual_residual

Get the Dual Residual
intf_shape

Get the shape of a value as an integer vector c(nrow, ncol)
cvxr_promote

Promote a scalar expression to the given shape
is_atom_quasiconcave

Check if Atom is Quasiconcave
is_atom_log_log_convex

Check if Atom is Log-Log Convex
is_dpp

Check DPP Compliance
is_dqcp

Check if Expression is DQCP-Compliant
make_sparse_diagonal_matrix

Make a CSC sparse diagonal matrix
linop_set_linop_data

Set a LinOp data sub-tree on a LinOp
math_atoms

Standard R Functions for CVXR Expressions
linop_set_dense_data

Set dense data on a LinOp
implies

Logical Implication
gen_lambda_max

Maximum generalized eigenvalue
geo_mean

(Weighted) geometric mean of a vector
diff_pos

The difference x - y with domain x > y > 0
entr

Create an entropy atom -x * log(x)
dist_ratio

Distance ratio
is_skew_symmetric

Check if Expression is Skew-Symmetric
length_expr

Length of a Vector (Last Nonzero Index)
is_scalar

Is the Expression a Scalar?
is_imag

Check if Expression is Imaginary
mixed_norm

Mixed norm (\(L_{p,q}\) norm): column-wise p-norm, then q-norm
mul_sign

Sign of a product of two expressions
linop_args_push_back

Append a child LinOp to the args list
linop_size_push_back

Push a dimension to the LinOp size vector
pos

Positive part: max(x, 0)
numeric_value

Compute the Numeric Value of an Atom
num_cones

Get the Number of Cones in a Constraint
indicator

Indicator function for constraints
is_atom_convex

Check if Atom is Convex
power

Create a Power atom
quad_form

Quadratic form x^T P x
linop_slice_push_back

Push a slice (index vector) to a LinOp
min_entries

Minimum entry of an expression
partial_optimize

Partial optimization transform
problem_data

Get Problem Data for a Solver
parameters

Get the Parameters in an Expression
one_minus_pos

The difference 1 - x with domain (0, 1)
objective

Get Problem Objective (read-only)
min_elemwise

Elementwise minimum of expressions
reduction-id-map

Reduction leaf-id maps
square

Square of an expression: x^2
resolvent

Resolvent inverse(sI - X)
sample_bounds

Sampling Bounds for NLP Random Restarts
problem_solution

Get the Raw Solution Object (deprecated)
reduction-chain-rule

Reduction chain-rule hooks (dict-in / dict-out)
quad_form_dpp_scope_active

Check if a quad_form DPP Scope is Active
is_nsd

Check if Expression is Negative Semidefinite
is_nonpos

Check if Expression is Non-Positive
.grad

Per-atom Subgradient Hook (private)
is_quasiconcave

Check if Expression is Quasiconcave
reshape_expr

Reshape an expression to a new shape
gradient

Access the gradient of a Variable or Parameter
dotsort

Weighted sorted dot product
dssamp

Direct Standardization: Sample
residual

Get the Residual of a Constraint
set_label

Attach a label to an expression
grad

Get the Gradient of an Expression
intf_is_hermitian

Check if a matrix is symmetric (and Hermitian for real case)
dual_cone

Get the Dual Cone Constraint
expr_sign

Get the DCP Sign of an Expression
expr_H

Conjugate-Transpose of an Expression
graph_implementation

Get the Graph Implementation of an Atom
is_quasiconvex

Check if Expression is Quasiconvex
vec_to_upper_tri

Reshape a vector into an upper triangular matrix
harmonic_mean

Harmonic mean: n / sum(1/x_i)
is_affine

Check if an Expression is Affine
is_atom_concave

Check if Atom is Concave
eye_minus_inv

Unity resolvent (I - X) inverse for positive square matrix X
status-constants

Solution Status Constants
is_atom_log_log_concave

Check if Atom is Log-Log Concave
size_metrics

Get Size Metrics for a Problem
log_sum_exp

Log-sum-exp: log(sum(exp(x)))
multiply

Elementwise multiplication (deprecated)
log_normcdf

Elementwise log of the standard normal CDF
is_smooth

Check if an Expression is Smooth
is_symmetric

Check if Expression is Symmetric
var_dict

Get all Variables of a Problem as a Named List
is_dgp

Check if a Constraint is DGP-Compliant
is_atom_smooth

Check if an Atom is Smooth
is_atom_quasiconvex

Check if Atom is Quasiconvex
violation

Get the Violation of a Constraint
is_quasilinear

Check if Expression is Quasilinear
is_mixed_integer

Check if a Problem is Mixed-Integer
is_nonneg

Check if Expression is Non-Negative
norm_inf

L-infinity norm of an expression
partial_trace

Partial trace of a tensor product expression
norm2

Euclidean norm (deprecated alias)
name

Get Expression Name
is_dnlp

Check if an Expression or Problem is DNLP-Compliant
is_linearizable_convex

Check if an Expression is Linearizable-Convex
intf_is_psd

Check if a symmetric matrix is PSD within tolerance
is_concave

Check if an Expression is Concave
is_log_log_affine

Check if Expression is Log-Log Affine
is_complex

Check if Expression is Complex
is_param_affine

Check if Expression is Parameter-Affine
lambda_sum_smallest

Sum of smallest k eigenvalues
is_real

Check if Expression is Real
kl_div

KL Divergence: x*log(x/y) - x + y
shape_from_args

Infer Shape from Arguments
partial_transpose

Partial transpose of a tensor product expression
scalarize

Scalarize multiple objectives into a single objective
lambda_sum_largest

Sum of largest k eigenvalues
kron

Kronecker product of two expressions
problem_unpack_results

Unpack Solver Results into a Problem
problem_status

Get the Solution Status of a Problem (deprecated)
matrix_frac

Matrix fractional function
matrix_trace

Trace of a square matrix expression
update_parameters

Update Parameters for DPP Fast Path
size

Get Expression Size
is_param_free

Check if Expression is Parameter-Free
norm1

L1 norm of an expression
smith_annotation

Smith Form Annotation for an Expression Node
p_norm

General p-norm of an expression
neg

Negative part: -min(x, 0)
param_dict

Get all Parameters of a Problem as a Named List
sigma_max

Maximum singular value
is_log_log_concave

Check if Expression is Log-Log Concave
sign_from_args

Infer Sign from Arguments
is_pos

Check if Expression is Strictly Positive
is_vector

Is the Expression a Vector?
is_log_log_convex

Check if Expression is Log-Log Convex
is_psd

Check if Expression is Positive Semidefinite
label

Get the label of an expression
label<-

Set the label of an expression
loggamma

Elementwise log of the gamma function
is_qpwa

Check if Expression is Quadratic or Piecewise Affine
is_quadratic

Check if an Expression is Quadratic
status

Get the Solution Status of a Problem
variables

Get the Variables in an Expression
linop_set_data_ndim

Set the data dimensionality on a LinOp
linop_new

Create a new C++ LinOp external pointer
log_det

Log-determinant
max_elemwise

Elementwise maximum of expressions
log1p_atom

Log(1 + x) -- elementwise
linop_set_type

Set the type of a LinOp
is_zero

Check if Expression is Zero
perspective

Perspective Transform
prod_entries

Product of entries along an axis
linop_set_sparse_data

Set sparse data on a LinOp
psolve

Solve a Convex Optimization Problem
max_entries

Maximum entry of an expression
ptp

Peak-to-peak (range): max(x) - min(x)
norm_nuc

Nuclear norm (sum of singular values)
normcdf

Standard Normal Cumulative Distribution Function
reduction_invert

Invert a Solution through a Reduction
solver_default_param

Standard Solver Parameter Mappings
logistic

Logistic function: log(1 + exp(x)) -- elementwise
sum_entries

Sum the entries of an expression
scalar_product

Scalar product (alias for vdot)
project

Project a Value onto the Domain of a Leaf
total_variation

Total variation of a vector or matrix
rel_entr

Relative Entropy: x*log(x/y)
visualize

Visualize the Canonicalization Pipeline of a CVXR Problem
tr_inv

Trace of matrix inverse
pf_eigenvalue

Perron-Frobenius eigenvalue of a positive matrix
tv

Total variation (deprecated alias)
sum_largest

Sum of k largest entries
quad_over_lin

Sum of squares divided by a scalar
solver_opts

Create Solver Options
solver_stats

Get Solver Statistics
value

Get the Numeric Value of an Expression
solver_name

Get Solver Name
reduction_accepts

Check if a Reduction Accepts a Problem
unpack_results

Unpack Results (backward-compatible alias)
xexp

x * exp(x) -- elementwise
scalene

Scalene penalty: alpha * pos(x) + beta * neg(x)
sum_squares

Sum of squares (= quad_over_lin(x, 1))
upper_tri

Extract strict upper triangle of a square matrix
solution

Get the Raw Solution Object
vdot

Vector dot product (inner product)
sum_signs

Sign of a sum of expressions
split_adjoint

Adjoint of split_solution
split_solution

Split a primal solution into per-variable arrays
reduction_apply

Apply a Reduction to a Problem
supports_quad_obj

Does Solver Support Quadratic Objectives?
real_expr

Extract Real Part of Expression
tree_copy

Deep Copy of an Expression Tree
validate_arguments

Validate Arguments to an Atom
save_dual_value

Save Dual Variable Values from Solver Output
solve_via_data

Solve via Raw Data
sum_smallest

Sum of k smallest entries
vec

Vectorize an expression (column vector)
with_dpp_scope

Execute Expression Within DPP Scope
vstack

Vertical concatenation of expressions
to_latex

Convert CVXR Object to LaTeX
solver-constants

Solver Name Constants
with_quad_form_dpp_scope

Execute Expression Within a quad_form DPP Scope
value<-

Set the Value of a Leaf Expression
DCPError

DCP Error condition
DiagMat

Extract Diagonal from a Matrix
ExpCone

Create an Exponential Cone Constraint