Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-align vignettes #61

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions vignettes/package-usage.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Using RcppEnsmallen in Your Own R Package"
author: James Joseph Balamuta
abstract: |
This vignette describes the best practices for using RcppEnsmallen in your
own R package.
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Using RcppEnsmallen in Your Own R Package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

# Overview

RcppEnsmallen is best used within an _R_ package.
The setup for `RcppEnsmallen`'s use mirrors that of other `Rcpp`-based projects.
In particular, the `DESCRIPTION` file requires the `LinkingTo` field and
two files inside the `src/` to establish the necessary compilation options.
In the next two sections, we show the modifications.

## DESCRIPTION file

Open your R package's `DESCRIPTION` file. Ensure that the `LinkingTo` directive
is present and contains:

```bash
LinkingTo: Rcpp, RcppArmadillo (>= 0.9.800.0.0), RcppEnsmallen (>= 0.2.20.0.1)
```

## Makevars inside the src/ Directory

Next, the `src/` directory must contain both a `Makevars` and `Makevars.win`
file. Each file must have the same contents of:

```bash
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
```

The `Makevars.win` file provides the appropriate configuration for Windows
while `Makevars` acts on Unix-alike systems like macOS, Linux, and Solaris.
32 changes: 5 additions & 27 deletions vignettes/using-rcppensmallen.Rmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: "Using RcppEnsmallen"
title: "Solving Linear Regression using Numeric Optimization"
author: James Joseph Balamuta and Dirk Eddelbuettel
abstract: |
Contained within are examples related to using RcppEnsmallen in everyday
work alongside of creating an _R_ package with it.
In this vignette, we describe how to use RcppEnsmallen in a standalone
C++ file.
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Using RcppEnsmallen}
%\VignetteIndexEntry{Solving Linear Regression using Numeric Optimization}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down Expand Up @@ -45,7 +45,7 @@ $$RSS\left( \beta \right) = \left( { \mathbf{y} - \mathbf{X} \beta } \right)^{\t

The objective function we wish to minimize would be defined as:

$$f(\beta) = \rVert y - X\beta\lVert_2$$
$$f(\beta) = \rVert \mathbf{y} - \mathbf{X}\beta\lVert_2$$

The gradient is defined as:

Expand Down Expand Up @@ -185,25 +185,3 @@ rownames(compare_coefs) = paste0("Beta", seq_len(nrow(compare_coefs)))
knitr::kable(compare_coefs, longtable = FALSE, caption = "Comparison of Estimated Coefficients")
```

# Package Usage

RcppEnsmallen is best used within an _R_ package. The setup for `RcppEnsmallen`'s
use mirrors that of other `Rcpp`-based projects. In particular, the
`DESCRIPTION` file requires the `LinkingTo` field to contain:

```bash
LinkingTo: Rcpp, RcppArmadillo (>= 0.9.800.0.0), RcppEnsmallen (>= 0.2.18.0.1)
```

Next, the `src/` directory must contain both a `Makevars` and `Makevars.win`
file with:

```bash
CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
```

The `Makevars.win` file provides the appropriate configuration for Windows
while `Makevars` acts on Unix-alike systems like macOS, Linux, and Solaris.