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

12,275

Version

1.9.2

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

August 24th, 2026

Functions in CVXR (1.9.2)

PowCone3D

Create a 3D Power Cone Constraint
PowConeND

Create an N-Dimensional Power Cone Constraint
Maximize

Create a Maximization Objective
Problem

Create an Optimization Problem
cvxr_outer

Outer product of two vectors
constraints

Get Problem Constraints (read-only)
SolverError

Solver Error condition
SizeMetrics

Problem Size Metrics
constants

Get the Constants in an Expression
NonNeg

Create a Non-Negative Constraint
Zero

Create a Zero Constraint
Minimize

Create a Minimization Objective
.grad

Per-atom Subgradient Hook (private)
constr_size

Get the Total Size of a Constraint
canonicalize

Canonicalize an Expression
cdiac

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

Create a Second-Order Cone Constraint
conv

1D discrete convolution
atoms

Get the Atoms in an Expression
.error_grad

Error Gradient (None for every variable)
cvxr_promote

Promote a scalar expression to the given shape
available_solvers

List available solvers
cumsum_axis

Cumulative sum along an axis
apply_param_jac

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

Convert a value to a CVXR Expression
ceil_expr

Elementwise Ceiling
condition_number

Condition number of a PSD matrix
atom_domain

Get Atom-Specific Domain Constraints
cvxr_std

Standard deviation of an expression
dotsort

Weighted sorted dot product
cvxr_var

Variance of an expression
dpp_scope_active

Check if DPP Scope is Active
dist_ratio

Distance ratio
huber

Create a Huber loss atom
domain

Get the Domain Constraints of an Expression
get_problem_data

Get Problem Data for a Solver (deprecated)
hstack

Horizontal concatenation of expressions
id

Get Expression ID
get_data

Get Atom-Specific Data
curvature

Get Expression Curvature
broadcast_args

Broadcast two expressions for binary operations
indicator

Indicator function for constraints
conj_expr

Elementwise Complex Conjugate
canonical_form

Get the Canonical Form
cone_sizes

Get the Sizes of Individual Cones
.column_grad

Per-column Subgradient for AxisAtoms (private)
.constant_grad

Gradient of a Constant Expression
diff_pos

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

List installed solvers
cvxr_diff

Compute kth Order Differences of an Expression
cvar

Conditional Value at Risk (CVaR)
dssamp

Direct Standardization: Sample
get_bounds

Lower/Upper Bounds of a Leaf
geo_mean

(Weighted) geometric mean of a vector
Xor

Logical XOR
dspop

Direct Standardization: Population
derivative

Apply the derivative of the solution map to perturbations
backward

Compute the gradient of a solution with respect to Parameters
eye_minus_inv

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

Conjugate-Transpose of an Expression
expr_copy

Shallow Copy of an Expression Tree Node
dual_cone

Get the Dual Cone Constraint
is_atom_log_log_concave

Check if Atom is Log-Log Concave
is_atom_log_log_convex

Check if Atom is Log-Log Convex
is_param_free

Check if Expression is Parameter-Free
format_labeled

Pretty-print an expression with labels substituted
implies

Logical Implication
gradient

Access the gradient of a Variable or Parameter
gen_lambda_max

Maximum generalized eigenvalue
floor_expr

Elementwise Floor
%<<%

Negative Semidefinite Constraint Operator
dual_residual

Get the Dual Residual
imag_expr

Extract Imaginary Part of Expression
graph_implementation

Get the Graph Implementation of an Atom
iff

Logical Biconditional
intf_sign

Determine the sign of a numeric value
intf_is_sparse

Check if a value is a sparse matrix
%>>%

Positive Semidefinite Constraint Operator
is_dgp

Check if a Constraint is DGP-Compliant
intf_is_hermitian

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

Convert a value to a numeric matrix or sparse matrix
is_decr

Check if Atom is Decreasing in an Argument
inv_pos

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

Check if Expression is Log-Log Affine
is_atom_quasiconcave

Check if Atom is Quasiconcave
is_symmetric

Check if Expression is Symmetric
is_vector

Is the Expression a Vector?
is_quasiconvex

Check if Expression is Quasiconvex
is_quasilinear

Check if Expression is Quasilinear
is_pos

Check if Expression is Strictly Positive
linop_set_data_ndim

Set the data dimensionality on a LinOp
is_nonneg

Check if Expression is Non-Negative
is_nonpos

Check if Expression is Non-Positive
is_atom_quasiconvex

Check if Atom is Quasiconvex
is_log_log_concave

Check if Expression is Log-Log Concave
is_zero

Check if Expression is Zero
is_scalar

Is the Expression a Scalar?
is_constant

Check if an Expression is Constant
is_concave

Check if an Expression is Concave
is_linearizable_concave

Check if an Expression is Linearizable-Concave
convolve

1D discrete convolution (numpy-style)
intf_shape

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

Geometric matrix multiplication A diamond X
bmat

Construct a Block Matrix
is_real

Check if Expression is Real
is_linearizable_convex

Check if an Expression is Linearizable-Convex
grad

Get the Gradient of an Expression
is_atom_convex

Check if Atom is Convex
is_atom_concave

Check if Atom is Concave
is_quadratic

Check if an Expression is Quadratic
is_mixed_integer

Check if a Problem is Mixed-Integer
is_psd

Check if Expression is Positive Semidefinite
is_matrix

Is the Expression a Matrix?
cummax_expr

Cumulative maximum along an axis
matrix_frac

Matrix fractional function
log_det

Log-determinant
math_atoms

Standard R Functions for CVXR Expressions
is_imag

Check if Expression is Imaginary
is_incr

Check if Atom is Increasing in an Argument
log_normcdf

Elementwise log of the standard normal CDF
cvxr_mean

Mean of an expression
linop_set_dense_data

Set dense data on a LinOp
is_convex

Check if an Expression is Convex
is_pwl

Check if Expression is Piecewise Linear
label

Get the label of an expression
is_quasiconcave

Check if Expression is Quasiconcave
numeric_value

Compute the Numeric Value of an Atom
objective

Get Problem Objective (read-only)
cvxr_norm

Compute a norm of an expression
deep_flatten

Recursively flatten a nested list of expressions into one column vector
linop_size_push_back

Push a dimension to the LinOp size vector
linop_set_type

Set the type of a LinOp
linop_args_push_back

Append a child LinOp to the args list
linop_new

Create a new C++ LinOp external pointer
is_dcp

Check if an Expression is DCP-Compliant
is_nsd

Check if Expression is Negative Semidefinite
is_dqcp

Check if Expression is DQCP-Compliant
delta

Access the perturbation delta of a Variable or Parameter
dual_value

Get the Dual Value of a Constraint
is_hermitian

Check if Expression is Hermitian
min_entries

Minimum entry of an expression
lambda_max

Maximum eigenvalue
expr_name

Get the Name of an Expression
entr

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

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

Get all Parameters of a Problem as a Named List
parameters

Get the Parameters in an Expression
is_param_affine

Check if Expression is Parameter-Affine
is_qp

Check if a Problem is a Quadratic Program
problem_solution

Get the Raw Solution Object (deprecated)
problem_status

Get the Solution Status of a Problem (deprecated)
expr_sign

Get the DCP Sign of an Expression
harmonic_mean

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

Sum of smallest k eigenvalues
neg

Negative part: -min(x, 0)
name

Get Expression Name
lambda_sum_largest

Sum of largest k eigenvalues
kl_div

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

Minimum eigenvalue
logistic

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

Check if Expression is Quadratic or Piecewise Affine
kron

Kronecker product of two expressions
label<-

Set the label of an expression
norm1

L1 norm of an expression
loggamma

Elementwise log of the gamma function
log_sum_exp

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

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

Sign of a product of two expressions
multiply

Elementwise multiplication (deprecated)
norm2

Euclidean norm (deprecated alias)
pf_eigenvalue

Perron-Frobenius eigenvalue of a positive matrix
max_entries

Maximum entry of an expression
make_sparse_diagonal_matrix

Make a CSC sparse diagonal matrix
pos

Positive part: max(x, 0)
min_elemwise

Elementwise minimum of expressions
length_expr

Length of a Vector (Last Nonzero Index)
matrix_trace

Trace of a square matrix expression
project

Project a Value onto the Domain of a Leaf
rel_entr

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

Reshape an expression to a new shape
problem_unpack_results

Unpack Solver Results into a Problem
p_norm

General p-norm of an expression
residual

Get the Residual of a Constraint
size_metrics

Get Size Metrics for a Problem
reduction_invert

Invert a Solution through a Reduction
resolvent

Resolvent inverse(sI - X)
max_elemwise

Elementwise maximum of expressions
psolve

Solve a Convex Optimization Problem
sigma_max

Maximum singular value
reduction_apply

Apply a Reduction to a Problem
shape_from_args

Infer Shape from Arguments
solver_stats

Get Solver Statistics
normcdf

Standard Normal Cumulative Distribution Function
prod_entries

Product of entries along an axis
quad_form_dpp_scope_active

Check if a quad_form DPP Scope is Active
sample_bounds

Sampling Bounds for NLP Random Restarts
quad_over_lin

Sum of squares divided by a scalar
sum_squares

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

Vector dot product (inner product)
variables

Get the Variables in an Expression
sum_largest

Sum of k largest entries
sum_entries

Sum the entries of an expression
solver_opts

Create Solver Options
vstack

Vertical concatenation of expressions
split_adjoint

Adjoint of split_solution
has_quadratic_term

Check if Expression Has a Quadratic Term
save_dual_value

Save Dual Variable Values from Solver Output
smith_annotation

Smith Form Annotation for an Expression Node
intf_is_psd

Check if a symmetric matrix is PSD within tolerance
xexp

x * exp(x) -- elementwise
with_quad_form_dpp_scope

Execute Expression Within a quad_form DPP Scope
split_solution

Split a primal solution into per-variable arrays
num_cones

Get the Number of Cones in a Constraint
solver_name

Get Solver Name
with_dpp_scope

Execute Expression Within DPP Scope
supports_quad_obj

Does Solver Support Quadratic Objectives?
inv_prod

Reciprocal of product of entries
power

Create a Power atom
partial_trace

Partial trace of a tensor product expression
partial_optimize

Partial optimization transform
square

Square of an expression: x^2
intf_is_skew_symmetric

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

Standard Solver Parameter Mappings
solver-constants

Solver Name Constants
sum_signs

Sign of a sum of expressions
sum_smallest

Sum of k smallest entries
problem_data

Get Problem Data for a Solver
real_expr

Extract Real Part of Expression
is_affine

Check if an Expression is Affine
size

Get Expression Size
set_label

Attach a label to an expression
scalene

Scalene penalty: alpha * pos(x) + beta * neg(x)
reduction-chain-rule

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

Infer Sign from Arguments
tr_inv

Trace of matrix inverse
unpack_results

Unpack Results (backward-compatible alias)
violation

Get the Violation of a Constraint
visualize

Visualize the Canonicalization Pipeline of a CVXR Problem
tree_copy

Deep Copy of an Expression Tree
tv

Total variation (deprecated alias)
to_latex

Convert CVXR Object to LaTeX
is_dnlp

Check if an Expression or Problem is DNLP-Compliant
is_atom_smooth

Check if an Atom is Smooth
is_dpp

Check DPP Compliance
is_log_log_convex

Check if Expression is Log-Log Convex
is_complex

Check if Expression is Complex
value

Get the Numeric Value of an Expression
vec_to_upper_tri

Reshape a vector into an upper triangular matrix
vec

Vectorize an expression (column vector)
total_variation

Total variation of a vector or matrix
linop_set_sparse_data

Set sparse data on a LinOp
is_lp

Check if a Problem is a Linear Program
is_smooth

Check if an Expression is Smooth
var_dict

Get all Variables of a Problem as a Named List
is_skew_symmetric

Check if Expression is Skew-Symmetric
linop_set_linop_data

Set a LinOp data sub-tree on a LinOp
log1p_atom

Log(1 + x) -- elementwise
linop_slice_push_back

Push a slice (index vector) to a LinOp
norm_nuc

Nuclear norm (sum of singular values)
norm_inf

L-infinity norm of an expression
quad_form

Quadratic form x^T P x
partial_transpose

Partial transpose of a tensor product expression
perspective

Perspective Transform
ptp

Peak-to-peak (range): max(x) - min(x)
reduction-id-map

Reduction leaf-id maps
reduction_accepts

Check if a Reduction Accepts a Problem
scalar_product

Scalar product (alias for vdot)
scalarize

Scalarize multiple objectives into a single objective
solution

Get the Raw Solution Object
solve_via_data

Solve via Raw Data
update_parameters

Update Parameters for DPP Fast Path
upper_tri

Extract strict upper triangle of a square matrix
status-constants

Solution Status Constants
status

Get the Solution Status of a Problem
validate_arguments

Validate Arguments to an Atom
value<-

Set the Value of a Leaf Expression
CVXR-package

CVXR: Disciplined Convex Optimization
ExpCone

Create an Exponential Cone Constraint
CallbackParam

Callback Parameter
Constant

Create a Constant Expression
And

Logical AND
Equality

Create an Equality Constraint
DiagMat

Extract Diagonal from a Matrix
FiniteSet

FiniteSet Constraint
DiagVec

Vector to Diagonal Matrix
Not

Logical NOT
Inequality

Create an Inequality Constraint
NonPos

Create a Non-Positive Constraint
Parameter

Create a Parameter
PSD

Create a Positive Semidefinite Constraint
Or

Logical OR
PartialProblem

Partial optimization of a Problem
DCPError

DCP Error condition
Variable

Create an Optimization Variable