volume
function (n) 
{
    as.kform(seq_len(n))
}

To cite the stokes package in publications, please use Hankin (2022); this function monograph discusses volume(). Spivak (1965), in a memorable passage, states:

The volume element

The fact that dimΛn(n)=1\operatorname{dim}\Lambda^n\left(\mathbb{R}^n\right)=1 is probably not new to you, since det\operatorname{det} is often defined as the unique element ωΛn(n)\omega\in\Lambda^n{\left(\mathbb{R}^n\right)} such that ω(e1,,en)=1\omega{\left(e_1,\ldots,e_n\right)}=1. For a general vector space VV there is no extra criterion of this sort to distinguish a particular ωΛn(n)\omega\in\Lambda^n{\left(\mathbb{R}^n\right)}. Suppose, however, that an inner product TT for VV is given. If v1,,vnv_1,\ldots,v_n and w1,,wnw_1,\ldots, w_n are two bases which are orthonormal with respect to TT, and the matrix A=(aij)A=\left(a_{ij}\right) is defined by wi=j=1naijvjw_i=\sum_{j=1}^n a_{ij}v_j, then

δij=T(wi,wj)=k,l=1naikajlT(vk,vl)=k=1naikajk.\delta_{ij}=T{\left(w_i,w_j\right)}= \sum_{k,l=1}^n a_{ik}a_{jl}\,T{\left(v_k,v_l\right)}= \sum_{k=1}^n a_{ik}a_{jk}.

In other words, if ATA^T denotes the transpose of the matrix AA, then we have AAT=IA\cdot A^T=I, so detA=±1\operatorname{det}A=\pm 1. It follows from Theorem 4-6 that if ωΛn(V)\omega\in\Lambda^n(V) satisfies ω(v1,,vn)=±1\omega{\left(v_1,\ldots,v_n\right)}=\pm 1, then ω(w1,,wn)=±1\omega{\left(w_1,\ldots,w_n\right)}=\pm 1. If an orientation μ\mu for VV has also been given, it follows that there is a unique ωΛn(V)\omega\in\Lambda^n(V) such that ω(v1,,vn)=1\omega\left(v_1,\ldots,v_n\right)=1 whenever v1,,vnv_1,\ldots,v_n is an orthornormal basis such that [v1,,vn]=μ\left[v_1,\ldots,v_n\right]=\mu. This unique ω\omega is called the volume element of VV, determined by the inner product TT and orientation μ\mu. Note that det\operatorname{det} is the volume element of n\mathbb{R}^n determined by the usual inner product and usual orientation, and that |det(v1,,vn)|\left|\operatorname{det}\left(v_1,\ldots,v_n\right)\right| is the volume of the parallelepiped spanned by the line segments from 00 to each of v1,,vnv_1,\ldots,v_n.

- Michael Spivak, 1969 (Calculus on Manifolds, Perseus books). Page 83

In the stokes package, function volume(n) returns the volume element on the usual basis, that is, ω(e1,,en)\omega{\left(e_1,\ldots,e_n\right)}. We will take n=7n=7 as an example:

(V <- volume(7))
## An alternating linear map from V^7 to R with V=R^7:
##                    val
##  1 2 3 4 5 6 7  =    1

We can verify Spivak’s reasoning as follows:

f <- as.function(V)
f(diag(7))
## [1] 1

Above, we see that ω(e1,,en)=1\omega{\left(e_1,\ldots,e_n\right)}=1. To verify that V(v1,,vn)=det(A)V{\left(v_1,\ldots,v_n\right)}=\operatorname{det}(A), where Aij=(vi)jA_{ij}=\left(v_i\right)_j:

A <- matrix(rnorm(49),7,7)
LHS <- f(A)
RHS <- det(A)
c(LHS=LHS,RHS=RHS,diff=LHS-RHS)
##      LHS      RHS     diff 
## 1.770074 1.770074 0.000000

Now we create w1,,wnw_1,\ldots,w_n, another orthonormal set. We may verify by generating a random orthogonal matrix and permuting its rows:

M1 <- qr.Q(qr(matrix(rnorm(49),7,7)))  # M1: a random orthogonal matrix
M2 <- M1[c(2,1,3,4,5,6,7),]            # M2: (odd) permutation of rows of M1
c(f(M1),f(M2))
## [1]  1 -1

Above we see that the volume element of M1 and M2 are ±1\pm1 to within numerical precision.

References

Hankin, R. K. S. 2022. “Stokes’s Theorem in R.” arXiv. https://doi.org/10.48550/ARXIV.2210.17008.
Spivak, M. 1965. Calculus on Manifolds. Addison-Wesley.