text:
## Models

We currently analyze and forecast rodent data at Portal using eleven models: AutoArima, ESSS, NaiveArima, nbGARCH, nbsGARCH, pevGARCH, jags_RW, jags_logistic, jags_logistic_covariates, jags_logistic_competition, jags_logistic_competition_covariates (WeecologyLab 2019). Each model has a function with its name (e.g., ESSS()) which is called from an associated R script in the models subdirectory with its name (e.g., ESSS.R)

### AutoArima

AutoArima (Automatic Auto-Regressive Integrated Moving Average) is a flexible Auto-Regressive Integrated Moving Average (ARIMA) model fit to the data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The model is selected and fitted using the auto.arima and forecast functions in the forecast package (Hyndman and Athanasopoulos 2013; Hyndman 2017) within the AutoArima() function. Generally, ARIMA models are defined according to three model structure parameters – the number of autoregressive terms (p), the degree of differencing (d), and the order of the moving average (q), and are represented as ARIMA(p, d, q) (Box and Jenkins 1970). While the auto.arima function allows for seasonal models, the seasonality is hard-coded to be on the same period as the sampling, which is not the case for the Portal rodent surveys. As a result, no seasonal models were evaluated. AutoArima is fit flexibly, such that the model parameters can vary from fit to fit.

### ESSS

ESSS (Exponential Smoothing State Space) is a flexible exponential smoothing state space model (Hyndman et al. 2008) fit to the interpolated data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The model is selected and fitted using the ets and forecast functions in the forecast package (Hyndman 2017) with the allow.multiplicative.trend argument set to TRUE within the ESSS() function. Models fit using ets implement what is known as the “innovations” approach to state space modeling, which assumes a single source of noise that is equivalent for the process and observation errors (Hyndman et al. 2008). In general, ESSS models are defined according to three model structure parameters – error type, trend type, and seasonality type (Hyndman et al. 2008). Each of the parameters can be an N (none), A (additive), or M (multiplicative) state (Hyndman et al. 2008). However, because of the difference in period between seasonality and sampling of the Portal rodents combined with the hard-coded single period of the ets function, we could not include the seasonal components to the ESSS model. ESSS is fit flexibly, such that the model parameters can vary from fit to fit.

### NaiveArima

NaiveArima (Naive Auto-Regressive Integrated Moving Average) is a fixed Auto-Regressive Integrated Moving Average (ARIMA) model of order (0,1,0) fit to the data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The model is selected and fitted using the Arima and forecast functions in the forecast package (Hyndman and Athanasopoulos 2013; Hyndman 2017) within the NaiveArima() function.

### nbGARCH

nbGARCH (Negative Binomial Auto-Regressive Conditional Heteroskedasticity) is a generalized autoregressive conditional heteroskedasticity (GARCH) model with overdispersion (i.e., a negative binomial response) fit to the interpolated data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The model for each species and the community total is selected and fitted using the tsglm function in the tscount package (Liboschik et al. 2017) within the nbGARCH() function. GARCH models are generalized ARMA models and are defined according to their link function, response distribution, and two model structure parameters – the number of autoregressive terms (p) and the order of the moving average (q), and are represented as GARCH(p, q) (Liboschik et al. 2017). The nbGARCH model is fit using the log link and a negative binomial response (modeled as an over-dispersed Poisson), as well as with p = 1 (first-order autoregression) and q = 12 (approximately yearly moving average). The tsglm function in the tscount package (Liboschik et al. 2017) uses a (conditional) quasi-likelihood based approach to inference and models the overdispersion as an additional parameter in a two-step approach. This two-stage approach has only been minimally evaluated, although preliminary simulation-based studies are promising (Liboschik, Fokianos, and Fried 2017).

### nbsGARCH

nbsGARCH (Negative Binomial Seasonal Auto-Regressive Conditional Heteroskedasticity) is a generalized autoregressive conditional heteroskedasticity (GARCH) model with overdispersion (i.e., a negative binomial response) with seasonal predictors modeled using two Fourier series terms (sin and cos of the fraction of the year) fit to the interpolated data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The model for each species and the community total is selected and fitted using the tsglm function in the tscount package (Liboschik et al. 2017) within the nbsGARCH() function. GARCH models are generalized ARMA models and are defined according to their link function, response distribution, and two model structure parameters – the number of autoregressive terms (p) and the order of the moving average (q), and are represented as GARCH(p, q) (Liboschik et al. 2017). The nbsGARCH model is fit using the log link and a negative binomial response (modeled as an over-dispersed Poisson), as well as with p = 1 (first-order autoregression) and q = 12 (approximately yearly moving average). The tsglm function in the tscount package (Liboschik et al. 2017) uses a (conditional) quasi-likelihood based approach to inference and models the overdispersion as an additional parameter in a two-step approach. This two-stage approach has only been minimally evaluated, although preliminary simulation-based studies are promising (Liboschik, Fokianos, and Fried 2017).

### pevGARCH

pevGARCH (Poisson Environmental Variable Auto-Regressive Conditional Heteroskedasticity) is a generalized autoregressive conditional heteroskedasticity (GARCH) model fit to the interpolated data at the composite (full site and just control plots) spatial level and both the composite (community) and the articulated (species) ecological levels. The response variable is Poisson, and a variety of environmental variables are considered as covariates. The model for each species is selected and fitted using the tsglm function in the tscount package (Liboschik et al. 2017) within the pevGARCH() function. GARCH models are generalized ARMA models and are defined according to their link function, response distribution, and two model structure parameters – the number of autoregressive terms (p) and the order of the moving average (q), and are represented as GARCH(p, q) (Liboschik et al. 2017). The pevGARCH model is fit using the log link and a Poisson response, as well as with p = 1 (first-order autoregression) and q = 12 (yearly moving average). The environmental variables potentially included in the model are min, mean, and max temperatures, precipitation, and NDVI. The tsglm function in the tscount package (Liboschik et al. 2017) uses a (conditional) quasi-likelihood based approach to inference. This approach has only been minimally evaluated for models with covariates, although preliminary simulation-based studies are promising (Liboschik, Fokianos, and Fried 2017). Each species is fit using the following (nonexhaustive) sets of the environmental covariates – [1] max temp, mean temp, precipitation, NDVI; [2] max temp, min temp, precipitation, NDVI; [3] max temp, mean temp, min temp, precipitation; [4] precipitation, NDVI; [5] min temp, NDVI; [6] min temp; [7] max temp; [8] mean temp; [9] precipitation; [10] NDVI; and [11] -none- (intercept-only). The single best model of the 11 is selected based on AIC.

### jags_RW

jags_RW fits a hierarchical log-scale density random walk model with a Poisson observation process using the JAGS (Just Another Gibbs Sampler) infrastructure (Plummer 2003) fit to the data at the composite (full site but just control plots) spatial level and the articulated (species) ecological level. Similar to the NaiveArima model, jags_RW has an ARIMA order of (0,1,0), but in jags_RW, it is the underlying density that takes a random walk on the log scale, whereas in NaiveArima, it is the raw counts that take a random walk on the observation scale. There are two process parameters – mu (the density of the species at the beginning of the time series) and sigma (the standard deviation of the random walk, which is Gaussian on the log scale). The observation model has no additional parameters. The prior distributions for mu is informed by the available data collected prior to the start of the data used in the time series. mu is normally distributed with a mean equal to the average log-scale density and a standard deviation of 0.04. Sigma was given a uniform distribution between 0 and 1.

### jags_logistic

jags_logistic fits a hierarchical log-scale density logistic growth model with a Poisson observation process using the JAGS (Just Another Gibbs Sampler) infrastructure (Plummer 2003) fit to the data at the composite (full site but just control plots) spatial level and the articulated (species) ecological level. Building upon the jags_RW model, jags_logistic expands upon the “process model” underlying the Poisson observations. There are four process parameters – mu (the density of the species at the beginning of the time series), sigma (the standard deviation of the random walk, which is Gaussian on the log scale), r (growth rate), and K (carrying capacity). The observation model has no additional parameters. The prior distributions for mu and K are informed by the available data collected prior to the start of the data used in the time series and sigma and r are set with vague priors. mu is normally distributed with a mean equal to the average log-scale density and a standard deviation of 0.04. K is modeled on the log-scale with a prior mean equal to the maximum of past counts and a standard deviation of 0.04. r is given a normal prior with mean 0 and standard deviation 0.04. Sigma was given a uniform distribution between 0 and 1.

### jags_logistic_covariates

jags_logistic_covariates fits a hierarchical log-scale density logistic growth model with a Poisson observation process using the JAGS (Just Another Gibbs Sampler) infrastructure (Plummer 2003) fit to the data at the composite (full site but just control plots) spatial level and the articulated (species) ecological level. Building upon the jags_logistic model, jags_logistic_covariates expands upon the “process model” underlying the Poisson observations. There are six process parameters – mu (the density of the species at the beginning of the time series), sigma (the standard deviation of the random walk, which is Gaussian on the log scale), and then intercept and slope parameters for r (growth rate) and K (carrying capacity) as a function of covariates (r being a function of the integrated warm rain over the past 3 months and K being a function of average NDVI over the past year). The observation model has no additional parameters. The prior distributions for mu and the K intercept are informed by the available data collected prior to the start of the data used in the time series and sigma and r are set with vague priors. mu is normally distributed with a mean equal to the average log-scale density and standard deviation 0.04. The K intercept is modeled on the log-scale with a prior mean equal to the maximum of past counts and standard deviation 0.04. The r intercept is given a normal prior with mean 0 and standard deviation 0.04. Sigma was given a uniform distribution between 0 and 1. The slopes for r and log-scale K were given priors with mean 0 and standard deviation 1.

### jags_logistic_competition

jags_logistic_competition fits a hierarchical log-scale density logistic growth model with a Poisson observation process using the JAGS (Just Another Gibbs Sampler) infrastructure (Plummer 2003) fit to the data at the composite (full site but just control plots) spatial level and the articulated (species) ecological level. Building upon the jags_logistic model, jags_logistic_competition expands upon the “process model” underlying the Poisson observations. There are six process parameters – mu (the density of the species at the beginning of the time series), sigma (the standard deviation of the random walk, which is Gaussian on the log scale), and then intercept and slope parameters for r (growth rate) and K (carrying capacity) as a function of competitior density (K being a function of current DO counts). The observation model has no additional parameters. The prior distributions for mu and the K intercept are informed by the available data collected prior to the start of the data used in the time series and sigma and r are set with vague priors. mu is normally distributed with a mean equal to the average log-scale density and standard deviation 0.04. The K intercept is modeled on the log-scale with a prior mean equal to the maximum of past counts and standard deviation 0.04. The r intercept is given a normal prior with mean 0 and standard deviation 0.04. Sigma was given a uniform distribution between 0 and 0.001. The slope for log-scale K was given a prior with mean 0 and standard deviation 1.

### jags_logistic_competition_covariates

jags_logistic_competition_covariates fits a hierarchical log-scale density logistic growth model with a Poisson observation process using the JAGS (Just Another Gibbs Sampler) infrastructure (Plummer 2003) fit to the data at the composite (full site but just control plots) spatial level and the articulated (species) ecological level. Building upon the jags_logistic model, jags_logistic_competition_covariates expands upon the “process model” underlying the Poisson observations. There are seven process parameters – mu (the density of the species at the beginning of the time series), sigma (the standard deviation of the random walk, which is Gaussian on the log scale), and then intercept and slope parameters for r (growth rate) and K (carrying capacity) as a function of competitior density (r being a function of the integrated warm rain over the past 3 months and K being a function of average NDVI over the past year as well as a function of current DO counts). The observation model has no additional parameters. The prior distributions for mu and the K intercept are informed by the available data collected prior to the start of the data used in the time series and sigma and r are set with vague priors. mu is normally distributed with a mean equal to the average log-scale density and standard deviation 0.04. The K intercept is modeled on the log-scale with a prior mean equal to the maximum of past counts and standard deviation 0.04. The r intercept is given a normal prior with mean 0 and standard deviation 0.04. Sigma was given a uniform distribution between 0 and 0.001. The slopes for r and log-scale K were given priors with mean 0 and standard deviation 1.

### Ensemble

In addition to the base models, we include a starting-point ensemble. Prior to v0.9.0, the ensemble was based on AIC weights, but in the shift to separating the interpolated from non-interpolated data in model fitting, we had to transfer to an unweighted average ensemble model. The ensemble mean is calculated as the mean of all model means and the ensemble variance is estimated as the sum of the mean of all model variances and the variance of the estimated mean, calculated using the unbiased estimate of sample variances.

## References

Box, G., and G. Jenkins. 1970. Time Series Analysis: Forecasting and Control. Holden-Day.

Hyndman, R. J. 2017. “forecast: Forecasting Functions for Time Series and Linear Models.” 2017. http://pkg.robjhyndman.com/forecast.

Hyndman, R. J., and G. Athanasopoulos. 2013. Forecasting: Principles and Practice. OTexts.

Hyndman, R. J., A. b. Koehler, J. K. Ord, and R. D. Snyder. 2008. Forecasting with Exponential Smoothing: The State Space Approach. Springer-Verlag.

Liboschik, T., K. Fokianos, and R. Fried. 2017. “tscount: An R Package for Analysis of Count Time Series Following Generalized Linear Models.” Journal of Statistical Software 82: 1–51. https://www.jstatsoft.org/article/view/v082i05.

Liboschik, T., R. Fried, K. Fokianos, and P. Probst. 2017. “tscount: Analysis of Count Time Series.” 2017. https://CRAN.R-project.org/package=tscount.

Plummer, M. 2003. “A Program for Analysis of Bayesian Graphical Models Using Gibbs Sampling.” Proceedings of the 3rd International Workshop on Distributed Statistical Computing. http://www.ci.tuwien.ac.at/Conferences/DSC-2003/Proceedings/Plummer.pdf.

WeecologyLab. 2019. “Portal Forecasting.” 2019. https://github.com/weecology/portalPredictions/.


text:
# Why is a symmetric traceless tensor zero when averaged over all directions?

In page 168 in Ref. [1], the authors search for a suitable order parameter for the nematic phase in liquid crystal. If $$\vec v^\alpha$$ is the direction of a single molecule, than due to the inversion symmetry, both $$\vec v^\alpha$$ and $$-\vec v^\alpha$$ contribute to order so the order parameter must be even in $$\vec v^\alpha$$. In addition, they want the order parameter to be $$0$$ in the disordered state. Since, I quote,

a symmetric traceless tensor will yield zero when averaged over all directions,

they define the following tensor

$$Q_{ij} = \frac{V}{N} \sum_{\alpha} (v_i^\alpha v_j^\alpha - \frac{1}{3} \delta_{ij}) \delta(\vec x -\vec x_{\alpha}) .$$

Now, I understant that this tensor is symmetric and traceless. I can also insert $$v_i^\alpha = [\cos \phi \sin \theta, \sin \phi \sin \theta, \cos \theta]$$ and see that the expression above is zero when averaged over all directions (but it does seem like magic).

So my question is, how general is the statement in the quote above?

For instance, in general, what does it mean to average a tensor over all directions? Does the quote require that the tensor has been defined in terms of quantity that has a direction in space (which is then the subject of averaging)? If this is the correct interpretation, is there an easy answer to why symmetric traceless tensors are zero when averaged over all directions?

[1] Chaikin, P. M., & Lubensky, T. C. (1995). Principles of condensed matter physics. Cambridge University Press.

• ...Because the said averaged value is just the trace up to a factor. – Valter Moretti Nov 10 '20 at 10:50
• How do you show that the average value of a tensor is proportional to its trace? Also, what does it even mean, in the general case, to take the average of a tensor? – KvanteKaffe Nov 10 '20 at 11:08
• Look at my answer. – Valter Moretti Nov 10 '20 at 11:16

The order parameter is a meso- or macroscopic quantity which is formed by adding together the tensor contributions from a bunch of different molecules: if each molecule $$\alpha$$ has a tensor $$T^{(\alpha)}$$, then the total order parameter is the sum of the $$T^{(\alpha)}$$ from all the molecules in the relevant sample of material, i.e., $$T = \sum_\alpha T^{(\alpha)},$$ or, when seen as a bilinear function with explicit arguments, $$T(u,v) = \sum_\alpha T^{(\alpha)}(u,v),$$ for arbitrary $$u,v\in\mathbb R^3$$.

The book's claim is that they want $$T$$ to be zero in the disordered state, in which the $$T^{(\alpha)}$$ themselves are pointing in every direction: that is,

• you fix some arbitrary reference tensor $$T^{(0)}$$,
• you assert that each of the $$T^{(\alpha)}$$s is a rotated version $$R[T^{(0)}]$$ of the reference tensor,
• and you assert that the ensemble combination $$\sum_\alpha$$ samples over all possible orientation rotations $$R$$, i.e., $$T(u,v) = \int_\mathrm{SO(3)} R[T^{(0)}](u,v) \:\mathrm dR.$$

Here the integral over $$\mathrm{SO}(3)$$ must be taken over the Haar measure of the group, which is the only definition of integration which is invariant w.r.t. the group action.

You might also be wondering what the rotated tensor "$$R[T^{(0)}](u,v)$$" means. In the abstract, it means that you rotate the tensor, but in practice, you can flip that "active transformation" view on its head into a "passive" one, by simply rotating the whole system ($$R[T^{(0)}]$$, $$u$$ and $$v$$) back to the original orientation, which gives you $$R[T^{(0)}](u,v) = T^{(0)}(R^{-1}u,R^{-1}v)$$ as a concrete recipe for evaluating $$R[T^{(0)}]$$.

The central claim here is the following:

Claim: this orientation averaging reduces the tensor to a multiple of the isotropic tensor $$\delta(u,v) = u\cdot v$$, with components proportional to the Kronecker delta $$\delta(e_i,e_j) = \delta_{ij}$$. Moreover, the coefficient is proportional to the trace of the reference tensor:

\begin{align} T(u,v) & = \int_\mathrm{SO(3)} R[T^{(0)}](u,v) \:\mathrm dR \\ & = \frac13 \mathrm{tr}(T^{(0)}) \delta(u,v) . \end{align}

(As pointed out by Valter Moretti, this is basically a whittled-down version of Schur's lemma, a central result in group representation theory which is well worth learning about if you feel like digging deeper.)

There are two main ways to understand this result: there is a fundamental core intuition that makes it work, but you can also prove it rigorously.

Intuition

The core of the result is that the orientation averaging means that $$T(u,v)$$ must be an isotropic tensor, i.e., it must be such that $$T(Ru,Rv) = T(u,v)$$ for every $$R\in\mathrm{SO}(3)$$. This is an extremely strong constraint: up to a constant multiple, there is only one isotropic tensor of rank two $$-$$ the Kronecker delta. This implies that $$T(u,v) = \lambda \delta(u,v)$$, and you just need to determine $$\lambda$$. This is extremely simple to do, by just taking the trace: $$\mathrm{tr}(T) = \lambda \: \mathrm{tr}(\delta) = \lambda \sum_{i=1}^3 \delta(e_i,e_i) = 3\lambda,$$ so $$\lambda = \frac 13 \mathrm{tr}(T)$$.

Proof

To complete the rigorous proof, thus, we only need to show that the Kronecker delta is the only isotropic tensor. As in V. Moretti's answer, the simplest way to do this is to consider the action of $$T$$ on a basis $$\{ e_i\}$$.

• For the off-diagonal elements, $$T(e_i,e_j)$$ with $$i\neq j$$, there exists a rotation $$R$$ (specifically, a rotation by $$180°$$ about $$e_i$$) for which $$Re_i=e_i$$ and $$Re_j=-e_j$$, which means that $$T(e_i,e_j) = T(Re_i,Re_j) = T(e_i,-e_j) = -T(e_i,e_j),$$ and therefore all the off-diagonal elements must vanish.
• With this in hand, we only need to show that all the diagonal elements are equal. Choosing $$e_i$$ and $$e_j$$ with $$i\neq j$$, a rotation by $$\pm 90°$$ about $$e_k$$ does $$Re_i=e_j$$, so $$T(e_i,e_i) = T(Re_i,Re_i) = T(e_j,e_j).$$

This completes the proof: $$T(u,v)$$ and $$\lambda\:\delta(u,v) = T(e_1,e_1)\delta(u,v)$$ coincide on a basis, so they must coincide everywhere.

• +1 Emilio, however I produced another proof, using Shur's lemma... – Valter Moretti Nov 10 '20 at 14:21

OK, another proof according to the Remark by Emilio that made clear the interpretation of the question. We have to average the tensor (as a bilinear map) in the space of the rotations. The only way to do it, as Emilio wrote, is to take an integral with respect to the normalized (left-invariant) Haar measure of $$SO(3)$$: $$\langle T\rangle_{SO(3)}(u,v) := \int_{SO(3)} T(R^tu,R^tv) dR$$ Since $$dB^tR = dR$$ for every $$B\in SO(3)$$, $$\langle T\rangle_{SO(3)}(Bu,Bv) = \int_{SO(3)} T(R^tBu,R^tBv) dR = \int_{SO(3)} T((B^tR)^tu,(B^tR)^tv) dR$$ $$= \int_{SO(3)} T((B^tR)^tu,(B^tR)^tv) dB^{t}R = \int_{SO(3)} T(R'^tu,R'^tv) dR' = \langle T\rangle_{SO(3)}(u,v)\:.$$ In matricial form, writing $$R$$ for $$B$$, $$u^tR \langle T\rangle_{SO(3)} R^tv = u^t\langle T\rangle_{SO(3)}v\:.$$ Since $$u,v$$ are arbitrary, $$R \langle T\rangle_{SO(3)} R^t = \langle T\rangle_{SO(3)}\:.$$ That is $$R \langle T\rangle_{SO(3)}= \langle T\rangle_{SO(3)}R \quad \forall R \in SO(3)\:.$$ Since the fundamental representation of $$SO(3)$$ is irreducible, Schur's lemma implies that, for some constant, $$t\in \mathbb{R}$$ $$\langle T\rangle_{SO(3)} = tI\:.$$ In particular, since every unit vector can be transformed to any other unit vector with a rotation, an orthonormal a basis is transformed into an orthonormal basis, and the trace does not depend on the basis, $$3t = \sum_{i=1}^3\langle T\rangle_{SO(3)}(e_i,e_i)$$ $$= tr\langle T\rangle_{SO(3)} = \int_{SO(3)} \sum_{i=1}^3T(R^te_i,R^te_i) dR = \int_{SO(3)} tr(T) dR = tr(T)\:.$$ In summary $$(\langle T\rangle_{SO(3)})_{ab} = \frac{1}{3}tr(T)\delta_{ab}\:.$$

• I agree -- the central claim at stake here is little more than a baby version of Schur's lemma. – Emilio Pisanty Nov 10 '20 at 15:19

Symmetry requirement is not necessary. Let us take an orthonormal basis $$e_1,e_2,e_3$$ and consider all the unit vectors $$n \in S^2$$. $$\int_{S^2} T(n,n) d n = \sum_{i,j=1}^3T(e_i,e_j) \int_{S^2} n^i n^j dn\:.$$ $$dn$$ is the standard rotation-invariant measure on $$S^2$$ with total value $$4\pi$$, i.e., referring to standard spherical coordinates $$dn = \sin \theta d\theta d\phi\:.$$ Now, for every choice of $$i=1,2,3$$ and $$j=1,2,3$$ with $$i\neq j$$ there is a rotation $$R$$ such that $$(Rn)^i=-n^i$$ but $$(Rn)^j = n^j$$. Since $$dn = dRn$$ we immediately have that $$\int_{S^2} n^i n^j dn= -\int_{S^2} n^i n^j dn= 0$$ if $$i\neq j$$. Therefore \begin{align} \sum_{i,j=1}^3T(e_i,e_j) \int_{S^2} n^i n^i dn & = \sum_{i=1}^3T(e_i,e_i) \int_{S^2} n^i n^i dn \\ & = T(e_1,e_1)\int_{S^2} (n^1)^2 dn + T(e_2,e_2)\int_{S^2} (n^2)^2 dn \\ & \qquad \quad + T(e_3,e_3)\int_{S^2} (n^3)^2 dn\:. \end{align} To conclude, observe that rotational invariance (as above) $$\int_{S^2} n^i n^i dn = d \quad \mbox{independently of i=1,2,3}$$ and thus $$4\pi = \int_{S^2} \sum_{i=1}^3 (n^i)^2 dn = 3d$$ which implies $$d = \frac{4\pi}{3}\:.$$ Inserting in the formula above \begin{align} \int_{S^2} T(n,n) d n & = \sum_{i,j=1}^3T(e_i,e_j) \int_{S^2} n^i n^j dn \\ \frac{4\pi}{3} \sum_{i=1}^3 T(e_i,e_i) & = \frac{4\pi}{3} \mathrm{tr}(T)\:. \end{align} In other words, averaging over all directions we obtain the trace up to the factor $$1/3$$: $$\langle T\rangle_{S^2} := \frac{1}{4\pi}\int_{S^2} T(n,n) d n = \frac{1}{3} \mathrm{tr}(T)\:.$$ Your hypothesis also requires $$\mathrm{tr}(T)=0$$ concluding the proof.

• I don't think this is quite the right calculation -- the OP's book is orientation-averaging the tensor itself, not its inputs. The result should be a (Kronecker delta) tensor, not a scalar. – Emilio Pisanty Nov 10 '20 at 13:26
• I see, one should take the averaged value in with respect to the rotations using the Haar measure. It is a similar computation... – Valter Moretti Nov 10 '20 at 13:50

The author here maybe concentrate on how to construct a tensor by a vector, so the average over direction means the average over direction of vector,namely $$\langle T_{ij}\rangle=\frac{1}{4\pi}\int T_{ij}d\Omega$$ where $$d\Omega$$ is the solid angle

The argument

a symmetric traceless tensor will yield zero when averaged over all directions

has some background on group theory -- the representation of SO(3) group. We could consider two vector $$U,V$$ and their tensor product $$U_iV_j$$ the problem is $$U_iV_j$$ could be divided into several part obeying different rules under rotation (that is to say, this is a reducible representation)

$$U_iV_j=\frac{1}{3}U\cdot V\delta_{ij}+\frac{1}{2}(U_iV_j-U_jV_i)+(\frac{U_iV_j-U_jV_i}{2}-\frac{U\cdot V}{3}\delta_{ij})$$

where the number of independent variable is $$3\times3=1+3+5$$

the first part is a scalar-- it's invariant under rotation. The second part is $$(U\times V)_k\epsilon_{ijk}$$ which transform like vector. In fact, the tensor is divided into terms called spherical tensor. The last part ,not that simple, tranform as l=2 sphere harmonic function. From the orthogonality of nonequivalent irreducible representation you could find that the integral (interpreted as the inner product of the l=2 with l=0 component) is zero.

Spherical tensor will be useful if you want to discuss items concerning angular momentum ,though they seems do little thing with what you ask. You may refer to books like Modern Quantum Mechanics J.J Sakurai if you're interested in this topic.

format: plain


text:
Measurement is the very basis of all scientific studies and experimentations. It also plays an important role in our day-to-day life. When it comes to building a table, putting a picture on the wall, timing a race, we need to be able to do measurements. Because it answers questions such as: how big, how long, how deep, how heavy the things are?

But to measure in a scientific way, we need to know some basic things about measurement. So in this tutorial, we are going to discuss some basic aspects of measurement, such as

• What is measurement?
• What is the physical quantity?
• What are the fundamental quantities?
• What are the derived quantities?
• What is the unit?
• What are the fundamental units?
• What are the derived units?
• What are the systems of units in measurements?
• The CGS units
• The MKS units
• The FPS units
• Instruments for measurement

# What is Measurement?

Measurement is a process that is associated with physical quantities of real-world objects, numbers, units, and various events. It is very basic in engineering, construction work, medical, or other technical fields, and can be used for almost every activity in our daily life.

Whatever we measure is called physical quantity in the language of science. To measure a physical quantity, we need two things, one is the numerical value and the other is its unit. However, in order to measure any physical quantity, we have to follow some rules.

In the process of measurement, we compare the given physical quantity with the known standard quantity of the same nature. For the measurement of a physical quantity, at first, we consider a constant quantity of the same nature as a standard and then we find the number which expresses, how many times the standard quantity is contained in the given physical quantity.

Now to know the details about this measurement we need to know about the physical quantity, its numerical value, and unit. So, if you are not familiar with physical quantities and units, then let's get first to know about all those things.

## What is Physical Quantity?

Anything that can be measured is called the physical quantity. For example, the mass and volume of an object, the density of an element, etc. But most of the things related to life we cannot measure such as - beauty, smell, taste, the hardness of the object, etc. So these are not physical quantities. These are qualitative observations that are usually observed with the senses.

Any physical quantity is expressed with a combination of a numerical value and a unit. For example, the physical quantity length can be quantified as 'n m', mass as 'n kg', and time as 'n s'. Where n is the numerical value and mkg, and s are the units.

There are two types of Physical Quantity - Fundamental or Base Quantity and Derived Quantity.

### What are the Fundamental Quantities?

The fundamental quantities are independent physical quantities, which help to obtain and find other physical quantities. These fundamental quantities are - length, mass, time, electric current, temperature, amount of substance, and luminous intensity.

### What are the Derived Quantities?

Derived quantities are such quantities that are derived from the combination of fundamental quantities through multiplication and division only (no addition or subtraction or any other sign).  For example - area, which is calculated by multiplying length by length (length × length), and volume which is length × length × length, and density which is calculated as the mass of the object divided by its volume (mass ÷ volume).

### What is the unit?

Unit is the quantity of a constant magnitude that is used to measure the magnitude of other quantities of the same nature. As in the example above, 'm' is used as the unit of a constant magnitude for length. Similarly, 'kg' is used for mass and 's' for time. But to accept any unit internationally, we need to be followed three essential conditions and these are

1. It should be possible to define the unit without ambiguity.

2. The unit should be reproducible.

3. The value of the unit should not change with space and time.

The units are of two kinds - fundamental units and derived units.

### What are the fundamental units?

The fundamental or basic units are independent units, which help to obtain and find other units. These units can neither be changed nor can be related to any other fundamental units. For example - The units of length, mass, time, electric current, temperature, amount of substance, and luminous intensity.

### What are the derived units?

Derived units are those units that depend on the fundamental units or which can be expressed in terms of the fundamental units. For example - The unit of area, volume, density, and force, etc.

In CGS unit system: The unit of area is centimeter square (cm × cm), the unit of volume is centimeter cube (cm × cm × cm), the unit of density is gram/centimeter cube {g/(cm × cm × cm)}, and the unit of force is Dyne {g × cm/( s × s)}, etc.

In SI or MKS unit system: The unit of area is meter square (m × m), the unit of volume is meter cube (m × m × m), the unit of density is kilogram/meter cube {kg/(m × m × m)}, and the unit of force is Newton {kg × m/ s × s)}, etc.

## What are the systems of units in measurements?

Basically, for a long time, three types of unit systems have been used all over the world.  These systems of units are C.G.S (centimeter-gram-second), M.K.S (meter-kilogram-second), and F.P.S (foot-pound-second).

The CGS units:

This is a French unit system. In this system, the unit of length is centimeter (cm), of mass is gram (g), and of time is second (s).

The MKS units:

This system of units is also known as the metric system of units. In this system, the unit of length is meter (m), of mass is kilogram (kg), and of time is second (s).

International System of Units (SI Units):

To measure the same physical quantity in the different unit systems,  many different measuring instruments have to be made for each unit system. Moreover, it is not possible to express the data obtained from different measurements in a coherent manner.

To address this problem the International Bureau of Weights and Measures (BIPM) recognized the only one unit system as the International System of Units. The units of the MKS system of three physical quantities (length, mass, and time) have been used in this system.

The FPS units:

This is a British unit system. In this system, the unit of length is foot (ft), of mass is pound (lb), and of time is second (s).

## Instruments for measurement

Here is a brief overview of the instruments used to measure the physical quantities we discussed earlier.

Instruments for measuring length: Length measuring instruments such as meter scale or ruler, tape measure, caliper (vernier calipers, dial calipers, and digital calipers), micrometer (digital and analog), feeler gauge, etc.

Instruments for measuring mass: Mass measuring instruments such as weighing scale, mass balance, etc. In physics, mass and weight are two different physical quantities. To measure the mass of an object, at first, we actually measure its weight and then divide it by the gravitational acceleration (g).

So mass is often measured by measuring the weight of the objects using a weighing scale, rather than a balance scale comparing it directly with known masses.

Instruments for measuring time: The instrument used to measure time is called a clock (analog and digital clock). But from ancient times people used instruments such as sundials and hourglass to keep tracking of time.

Instruments for measuring electric current: The instrument used to measure electric current is called an ammeter.

Instruments for measuring temperature: There are many methods have been developed to measure temperature. Most of these depend on measuring some physical property of the given material that varies with temperature. One of the most common instruments used to measure temperature is called a thermometer.

Other important instruments for measuring temperature are thermocouples, thermistors, resistance temperature detector (RTD), pyrometer, langmuir probes (for electron temperature of a plasma), and infrared thermometers, etc.

Instruments for measuring amount of substance: There are no measuring instruments that directly measure moles ( or amount of substance). But we can measure the amount of a substance from other measured quantities such as mass and volume.

Instruments for measuring luminous intensity: The instrument used to measure luminous intensity is called a photometer.

Instruments for measuring area: The instrument used to measure area is called a planimeter ( types - polar, linear, and Prytz or "hatchet" planimeter), which is also known as a platometer. It is used to determine the area of an arbitrary two-dimensional shape.

To measure area we also use linear measuring instruments like - tape measure, ruler (to measure length and width), etc.

Instruments for measuring volume: Volumetric Vessels such as Beakers and Erlenmeyer flasks can be used to measure the volume of liquids.

Instruments for measuring density: The instrument used to measure the density of a liquid is called a hydrometer.

Instruments for measuring acceleration: The instrument used to measure the acceleration is called an accelerometer.

Instruments for measuring force: The instrument used to measure the force is called a force gauge (also called a force meter).

Instruments for measuring pressure: The instrument used to measure the atmospheric pressure is called a barometer. Other important instruments for measuring pressure are piezometer or pressure tube, manometers, bourdon gauge, diaphragm pressure gauge, etc.


text:
#### You may also like

A circle is inscribed in an equilateral triangle. Smaller circles touch it and the sides of the triangle, the process continuing indefinitely. What is the sum of the areas of all the circles?

### Lunar Leaper

Gravity on the Moon is about 1/6th that on the Earth. A pole-vaulter 2 metres tall can clear a 5 metres pole on the Earth. How high a pole could he clear on the Moon?

### The Root Cause

Prove that if a is a natural number and the square root of a is rational, then it is a square number (an integer n^2 for some integer n.)

# Can You Prove It?

##### Stage: 5 Challenge Level:
Here are six statements for you to try to prove clearly and concisely. Once you have had a go, follow the links to see how other students solved each one.

Perfectly Square

We are first given that: $$x_1 = 2^2 + 3^2 + 6^2$$ $$x_2 = 3^2 + 4^2 + 12^2$$ $$x_3 = 4^2 + 5^2 + 20^2$$ Then show that $x_n$ is always a perfect square.

Always Perfect
Prove that if you add 1 to the product of four consecutive whole numbers the answer is ALWAYS a perfect square.

Unit Interval
Take any two numbers between $0$ and $1$. Prove that the sum of the numbers is always less than one plus their product.

That is, if $0< x< 1$ and $0< y< 1$ then prove

$$x+y< 1+xy$$.

Sums of Squares
$2(5^2 + 3^2) = 2(25 + 9) = 68 = 64 + 4 = 8^2 + 2^2$
$2(7^2 + 4^2) = 2(49 + 16) = 130 = 121 + 9 = 11^2 + 3^2$
Prove that if you double the sum of two squares you get the sum of two squares.

For What?
Prove that if the integer $n$ is divisible by $4$ then it can be written as the difference of two squares.

Mod 3
Prove that if $a^2+b^2$ is a multiple of $3$ then both $a$ and $b$ are multiples of $3$.


text:
# rlang 0.4.6 2020-05-02

• !!! now uses a combination of length(), names(), and [[ to splice S3 and S4 objects. This produces more consistent behaviour than as.list() on a wider variety of vector classes (#945, tidyverse/dplyr#4931).

# rlang 0.4.5 2020-03-01

• set_names(), is_formula(), and names2() are now implemented in C for efficiency.

• The .data pronoun now accepts symbol subscripts (#836).

• Quosure lists now explicitly inherit from "list". This makes them compatible with the vctrs package (#928).

• All rlang options are now documented in a centralised place, see ?rlang::faq-options (#899, @smingerson).

• Fixed crash when env_bindings_are_lazy() gets improper arguments (#923).

• arg_match() now detects and suggests possible typos in provided arguments (@jonkeane, #798).

• arg_match() now gives an error if argument is of length greater than 1 and doesn’t exactly match the values input, similar to base match.arg (#914, @AliciaSchep)

# rlang 0.4.4 2020-01-28

• Maintenance release for CRAN.

# rlang 0.4.3 2020-01-24

• You can now use glue syntax to unquote on the LHS of :=. This syntax is automatically available in all functions taking dots with list2() and enquos(), and thus most of the tidyverse. Note that if you use the glue syntax in an R package, you need to import glue.

A single pair of braces triggers normal glue interpolation:

df <- data.frame(x = 1:3)

suffix <- "foo"
df %>% dplyr::mutate("var_{suffix}" := x * 2)
#>   x var_foo
#> 1 1       2
#> 2 2       4
#> 3 3       6

Using a pair of double braces is for labelling a function argument. Technically, this is shortcut for "{as_label(enquo(arg))}". The syntax is similar to the curly-curly syntax for interpolating function arguments:

my_wrapper <- function(data, var, suffix = "foo") {
data %>% dplyr::mutate("{{ var }}_{suffix}" := {{ var }} * 2)
}
df %>% my_wrapper(x)
#>   x x_foo
#> 1 1     2
#> 2 2     4
#> 3 3     6

df %>% my_wrapper(sqrt(x))
#>   x sqrt(x)_foo
#> 1 1    2.000000
#> 2 2    2.828427
#> 3 3    3.464102
• Fixed a bug in magrittr backtraces that caused duplicate calls to appear in the trace.

• Fixed a bug in magrittr backtraces that caused wrong call indices.

• Empty backtraces are no longer shown when rlang_backtrace_on_error is set.

• The tidy eval .env pronoun is now exported for documentation purposes.

• warn() and abort() now check that either class or message was supplied. inform() allows sending empty message as it is occasionally useful for building user output incrementally.

• flatten() fails with a proper error when input can’t be flattened (#868, #885).

• inform() now consistently appends a final newline to the message (#880).

• cnd_body.default() is now properly registered.

• cnd_signal() now uses the same approach as abort() to save unhandled errors to last_error().

• Parsable constants like NaN and NA_integer_ are now deparsed by expr_deparse() in their parsable form (#890).

• Infix operators now stick to their LHS when deparsed by expr_deparse() (#890).

# rlang 0.4.2 2019-11-23

• New cnd_header(), cnd_body() and cnd_footer() generics. These are automatically called by conditionMessage.rlang_error(), the default method for all rlang errors.

Concretely, this is a way of breaking up lazy generation of error messages with conditionMessage() into three independent parts. This provides a lot of flexibility for hierarchies of error classes, for instance you could inherit the body of an error message from a parent class while overriding the header and footer.

• The reminder to call last_error() is now less confusing thanks to a suggestion by @markhwhiteii.

• The functions prefixed in scoped_ have been renamed to use the more conventional local_ prefix. For instance, scoped_bindings() is now local_bindings(). The scoped_ functions will be deprecated in the next significant version of rlang (0.5.0).

• The .subclass argument of abort(), warn() and inform() has been renamed to class. This is for consistency with our conventions for class constructors documented in https://adv-r.hadley.nz/s3.html#s3-subclassing.

• inform() now prints messages to the standard output by default in interactive sessions. This makes them appear more like normal output in IDEs such as RStudio. In non-interactive sessions, messages are still printed to standard error to make it easy to redirect messages when running R scripts (#852).

• Fixed an error in trace_back() when the call stack contains a quosured symbol.

• Backtrace is now displayed in full when an error occurs in non-interactive sessions. Previously the backtraces of parent errors were left out.

# rlang 0.4.1 2019-10-24

• New experimental framework for creating bulleted error messages. See ?cnd_message for the motivation and an overwiew of the tools we have created to support this approach. In particular, abort() now takes character vectors to assemble a bullet list. Elements named x are prefixed with a red cross, elements named i are prefixed with a blue info symbol, and unnamed elements are prefixed with a bullet.

• Capture of backtrace in the context of rethrowing an error from an exiting handler has been improved. The tryCatch() context no longer leaks in the high-level backtrace.

• Printing an error no longer recommends calling last_trace(), unless called from last_error().

• env_clone() no longer recreates active bindings and is now just an alias for env2list(as.list(env)). Unlike as.list() which returns the active binding function on R < 4.0, the value of active bindings is consistently used in all versions.

• The display of rlang errors derived from parent errors has been improved. The simplified backtrace (as printed by rlang::last_error()) no longer includes the parent errors. On the other hand, the full backtrace (as printed by rlang::last_trace()) now includes the backtraces of the parent errors.

• cnd_signal() has improved support for rlang errors created with error_cnd(). It now records a backtrace if there isn’t one already, and saves the error so it can be inspected with rlang::last_error().

• rlang errors are no longer formatted and saved through conditionMessage(). This makes it easier to use a conditionMessage() method in subclasses created with abort(), which is useful to delay expensive generation of error messages until display time.

• abort() can now be called without error message. This is useful when conditionMessage() is used to generate the message at print-time.

• Fixed an infinite loop in eval_tidy(). It occurred when evaluating a quosure that inherits from the mask itself.

• env_bind()’s performance has been significantly improved by fixing a bug that caused values to be repeatedly looked up by name.

• cnd_muffle() now checks that a restart exists before invoking it. The restart might not exist if the condition is signalled with a different function (such as stop(warning_cnd)).

• trace_length() returns the number of frames in a backtrace.

• Added internal utility cnd_entrace() to add a backtrace to a condition.

• rlang::last_error() backtraces are no longer displayed in red.

• x %|% y now also works when y is of same length as x (@rcannood, #806).

• Empty named lists are now deparsed more explicitly as "<named list>".

• Fixed chr() bug causing it to return invisibly.

# rlang 0.4.0 2019-06-25

## Tidy evaluation

### Interpolate function inputs with the curly-curly operator

The main change of this release is the new tidy evaluation operator {{. This operator abstracts the quote-and-unquote idiom into a single interpolation step:

my_wrapper <- function(data, var, by) {
data %>%
group_by({{ by }}) %>%
summarise(average = mean({{ var }}, na.rm = TRUE))
}

{{ var }} is a shortcut for !!enquo(var) that should be easier on the eyes, and easier to learn and teach.

Note that for multiple inputs, the existing documentation doesn’t stress enough that you can just pass dots straight to other tidy eval functions. There is no need for quote-and-unquote unless you need to modify the inputs or their names in some way:

my_wrapper <- function(data, var, ...) {
data %>%
group_by(...) %>%
summarise(average = mean({{ var }}, na.rm = TRUE))
}

### More robust .env pronoun

Another improvement to tidy evaluation should make it easier to use the .env pronoun. Starting from this release, subsetting an object from the .env pronoun now evaluates the corresponding symbol. This makes .env more robust, in particular in magrittr pipelines. The following example would previously fail:

foo <- 10
mtcars %>% mutate(cyl = cyl * .env$foo) This way, using the .env pronoun is now equivalent to unquoting a constant objects, but with an easier syntax: mtcars %>% mutate(cyl = cyl * !!foo) Note that following this change, and despite its name, .env is no longer referring to a bare environment. Instead, it is a special shortcut with its own rules. Similarly, the .data pronoun is not really a data frame. ## New functions and features • New pairlist2() function with splicing support. It preserves missing arguments, which makes it useful for lists of formal parameters for functions. • is_bool() is a scalar type predicate that checks whether its input is a single TRUE or FALSE. Like is_string(), it returns FALSE when the input is missing. This is useful for type-checking function arguments (#695). • is_string() gains a string argument. is_string(x, "foo") is a shortcut for is_character(x) && length(x) == 1 && identical(x, "foo"). • Lists of quosures now have pillar methods for display in tibbles. • set_names() now names unnamed input vectors before applying a function. The following expressions are now equivalent: letters %>% set_names() %>% set_names(toupper) letters %>% set_names(toupper) • You can now pass a character vector as message argument for abort(), warn(), inform(), and signal(). The vector is collapsed to a single string with a "\n" newline separating each element of the input vector (#744). • maybe_missing() gains a default argument. • New functions for weak references: new_weakref(), weakref_key(), weakref_value(), and is_weakref() (@wch, #787). ## Performance • The performance of exec() has been improved. It is now on the same order of performance as do.call(), though slightly slower. • call2() now uses the new pairlist2() function internally. This considerably improves its performance. This also means it now preserves empty arguments: call2("fn", 1, , foo = ) #> fn(1, , foo = ) ## Bugfixes and small improvements • with_handlers() now installs calling handlers first on the stack, no matter their location in the argument list. This way they always take precedence over exiting handlers, which ensures their side effects (such as logging) take place (#718). • In rlang backtraces, the global:: prefix is now only added when the function directly inherits from the global environment. Functions inheriting indirectly no longer have a namespace qualifier (#733). • options(error = rlang::entrace) now has better support for errors thrown from C (#779). It also saves structured errors in the error field of rlang::last_error(). • ns_env() and ns_env_name() (experimental functions) now support functions and environments consisently. They also require an argument from now on. • is_interactive() is aware of the TESTTHAT environment variable and returns FALSE when it is "true" (@jennybc, #738). • fn_fmls() and variants no longer coerce their input to a closure. Instead, they throw an error. • Fixed an issue in knitr that caused backtraces to print even when error = TRUE. • The return object from as_function() now inherits from "function" (@richierocks, #735). ## Lifecycle We commit to support 5 versions of R. As R 3.6 is about to be released, rlang now requires R 3.2 or greater. We’re also continuing our efforts to streamline and narrow the rlang API. • modify() and prepend() (two experimental functions marked as in the questioning stage since rlang 0.3.0) are now deprecated. Vector functions are now out of scope for rlang. They might be revived in the vctrs or funs packages. • exiting() is soft-deprecated because with_handlers() treats handlers as exiting by default. • The vector constructors like lgl() or new_logical() are now in the questioning stage. They are likely to be moved to the vctrs package at some point. Same for the missing values shortcuts like na_lgl. • as_logical(), as_integer(), etc have been soft-deprecated in favour of vctrs::vec_cast(). • type_of(), switch_type(), coerce_type(), and friends are soft-deprecated. • The encoding and locale API was summarily archived. This API didn’t bring any value and wasn’t used on CRAN. • lang_type_of(), switch_lang(), and coerce_lang() were archived. These functions were not used on CRAN or internally. • Subsetting quosures with [ or [[ is soft-deprecated. • All functions that were soft-deprecated, deprecated, or defunct in previous releases have been bumped to the next lifecycle stage. # rlang 0.3.2 2019-03-21 • Fixed protection issue reported by rchk. • The experimental option rlang__backtrace_on_error is no longer experimental and has been renamed to rlang_backtrace_on_error. • New “none” option for rlang_backtrace_on_error. • Unary operators applied to quosures now give better error messages. • Fixed issue with backtraces of warnings promoted to error, and entraced via withCallingHandlers(). The issue didn’t affect entracing via top level options(error = rlang::entrace) handling. # rlang 0.3.1 2019-01-08 This patch release polishes the new backtrace feature introduced in rlang 0.3.0 and solves bugs for the upcoming release of purrr 0.3.0. It also features as_label() and as_name() which are meant to replace quo_name() in the future. Finally, a bunch of deparsing issues have been fixed. ## Backtrace fixes • New entrace() condition handler. Add this to your RProfile to enable rlang backtraces for all errors, including warnings promoted to errors: if (requireNamespace("rlang", quietly = TRUE)) { options(error = rlang::entrace) } This handler also works as a calling handler: with_handlers( error = calling(entrace), foo(bar) ) However it’s often more practical to use with_abort() in that case: with_abort(foo(bar)) • with_abort() gains a classes argument to promote any kind of condition to an rlang error. • New last_trace() shortcut to print the backtrace stored in the last_error(). • Backtrace objects now print in full by default. • Calls in backtraces are now numbered according to their position in the call tree. The numbering is non-contiguous for simplified backtraces because of omitted call frames. • catch_cnd() gains a classes argument to specify which classes of condition to catch. It returns NULL if the expected condition could not be caught (#696). ## as_label() and as_name() The new as_label() and as_name() functions should be used instead of quo_name() to transform objects and quoted expressions to a string. We have noticed that tidy eval users often use quo_name() to extract names from quosured symbols. This is not a good use for that function because the way quo_name() creates a string is not a well defined operation. For this reason, we are replacing quo_name() with two new functions that have more clearly defined purposes, and hopefully better names reflecting those purposes. Use as_label() to transform any object to a short human-readable description, and as_name() to extract names from (possibly quosured) symbols. Create labels with as_label() to: • Display an object in a concise way, for example to labellise axes in a graphical plot. • Give default names to columns in a data frame. In this case, labelling is the first step before name repair. We expect as_label() to gain additional parameters in the future, for example to control the maximum width of a label. The way an object is labelled is thus subject to change. On the other hand, as_name() transforms symbols back to a string in a well defined manner. Unlike as_label(), as_name() guarantees the roundtrip symbol -> string -> symbol. In general, if you don’t know for sure what kind of object you’re dealing with (a call, a symbol, an unquoted constant), use as_label() and make no assumption about the resulting string. If you know you have a symbol and need the name of the object it refers to, use as_name(). For instance, use as_label() with objects captured with enquo() and as_name() with symbols captured with ensym(). Note that quo_name() will only be soft-deprecated at the next major version of rlang (0.4.0). At this point, it will start issuing once-per-session warnings in scripts, but not in packages. It will then be deprecated in yet another major version, at which point it will issue once-per-session warnings in packages as well. You thus have plenty of time to change your code. ## Minor fixes and features • New is_interactive() function. It serves the same purpose as base::interactive() but also checks if knitr is in progress and provides an escape hatch. Use with_interactive() and scoped_interactive() to override the return value of is_interactive(). This is useful in unit tests or to manually turn on interactive features in RMarkdown outputs • calling() now boxes its argument. • New done() function to box a value. Done boxes are sentinels to indicate early termination of a loop or computation. For instance, it will be used in the purrr package to allow users to shortcircuit a reduction or accumulation. • new_box() now accepts additional attributes passed to structure(). • Fixed a quotation bug with binary operators of zero or one argument such as /(1) (#652). They are now deparsed and printed properly as well. • New call_ns() function to retrieve the namespace of a call. Returns NULL if the call is not namespaced. • Top-level S3 objects are now deparsed properly. • Empty { blocks are now deparsed on the same line. • Fixed a deparsing issue with symbols containing non-ASCII characters (#691). • expr_print() now handles [ and [[ operators correctly, and deparses non-syntactic symbols with backticks. • call_modify() now respects ordering of unnamed inputs. Before this fix, it would move all unnamed inputs after named ones. • as_closure() wrappers now call primitives with positional arguments to avoid edge case issues of argument matching. • as_closure() wrappers now dispatch properly on methods defined in the global environment (tidyverse/purrr#459). • as_closure() now supports both base-style (e1 and e2) and purrr-style (.x and .y) arguments with binary primitives. • exec() takes .fn as first argument instead of f, for consistency with other rlang functions. • Fixed infinite loop with quosures created inside a data mask. • Base errors set as parent of rlang errors are now printed correctly. # rlang 0.3.0 2018-10-22 ## Breaking changes The rlang API is still maturing. In this section, you’ll find hard breaking changes. See the life cycle section below for an exhaustive list of API changes. • quo_text() now deparses non-syntactic symbols with backticks: quo_text(sym("foo+")) #> [1] "foo+" This caused a number of issues in reverse dependencies as quo_text() tends to be used for converting symbols to strings. quo_text() and quo_name() should not be used for this purpose because they are general purpose deparsers. These functions should generally only be used for printing outputs or creating default labels. If you need to convert symbols to strings, please use as_string() rather than quo_text(). We have extended the documentation of ?quo_text and ?quo_name to make these points clearer. • exprs() no longer flattens quosures. exprs(!!!quos(x, y)) is now equivalent to quos(x, y). • The sentinel for removing arguments in call_modify() has been changed from NULL to zap(). This breaking change is motivated by the ambiguity of NULL with valid argument values. call_modify(call, arg = NULL) # Add arg = NULL to the call call_modify(call, arg = zap()) # Remove the arg argument from the call • The %@% operator now quotes its input and supports S4 objects. This makes it directly equivalent to @ except that it extracts attributes for non-S4 objects (#207). • Taking the env_parent() of the empty environment is now an error. ## Summary The changes for this version are organised around three main themes: error reporting, tidy eval, and tidy dots. • abort() now records backtraces automatically in the error object. Errors thrown with abort() invite users to call rlang::last_error() to see a backtrace and help identifying where and why the error occurred. The backtraces created by rlang (you can create one manually with trace_back()) are printed in a simplified form by default that removes implementation details from the backtrace. To see the full backtrace, call summary(rlang::last_error()). abort() also gains a parent argument. This is meant for situations where you’re calling a low level API (to download a file, parse a JSON file, etc) and would like to intercept errors with base::tryCatch() or rlang::with_handlers() and rethrow them with a high-level message. Call abort() with the intercepted error as the parent argument. When the user prints rlang::last_error(), the backtrace will be shown in two sections corresponding to the high-level and low-level contexts. In order to get segmented backtraces, the low-level error has to be thrown with abort(). When that’s not the case, you can call the low-level function within with_abort() to automatically promote all errors to rlang errors. • The tidy eval changes are mostly for developers of data masking APIs. The main user-facing change is that .data[[ is now an unquote operator so that var in .data[[var]] is never masked by data frame columns and always picked from the environment. This makes the pronoun safe for programming in functions. • The !!! operator now supports all classed objects like factors. It calls as.list() on S3 objects and as(x, "list") on S4 objects. • dots_list() gains several arguments to control how dots are collected. You can control the selection of arguments with the same name with .homonyms (keep first, last, all, or abort). You can also elect to preserve empty arguments with .preserve_empty. ## Conditions and errors • New trace_back() captures a backtrace. Compared to the base R traceback, it contains additional structure about the relationship between frames. It comes with tools for automatically restricting to frames after a certain environment on the stack, and to simplify when printing. These backtraces are now recorded in errors thrown by abort() (see below). • abort() gains a parent argument to specify a parent error. This is meant for situations where a low-level error is expected (e.g. download or parsing failed) and you’d like to throw an error with higher level information. Specifying the low-level error as parent makes it possible to partition the backtraces based on ancestry. • Errors thrown with abort() now embed a backtrace in the condition object. It is no longer necessary to record a trace with a calling handler for such errors. • with_abort() runs expressions in a context where all errors are promoted to rlang errors and gain a backtrace. • Unhandled errors thrown by abort() are now automatically saved and can be retrieved with rlang::last_error(). The error prints with a simplified backtrace. Call summary(last_error()) to see the full backtrace. • New experimental option rlang__backtrace_on_error to display backtraces alongside error messages. See ?rlang::abort for supported options. • The new signal() function completes the abort(), warn() and inform() family. It creates and signals a bare condition. • New interrupt() function to simulate an user interrupt from R code. • cnd_signal() now dispatches messages, warnings, errors and interrupts to the relevant signalling functions (message(), warning(), stop() and the C function Rf_onintr()). This makes it a good choice to resignal a captured condition. • New cnd_type() helper to determine the type of a condition ("condition", "message", "warning", "error" or "interrupt"). • abort(), warn() and inform() now accepts metadata with .... The data are stored in the condition and can be examined by user handlers. Consequently all arguments have been renamed and prefixed with a dot (to limit naming conflicts between arguments and metadata names). • with_handlers() treats bare functions as exiting handlers (equivalent to handlers supplied to tryCatch()). It also supports the formula shortcut for lambda functions (as in purrr). • with_handlers() now produces a cleaner stack trace. ## Tidy dots • The input types of !!! have been standardised. !!! is generally defined on vectors: it takes a vector (typically, a list) and unquotes each element as a separate argument. The standardisation makes !!! behave the same in functions taking dots with list2() and in quoting functions. !!! accepts these types: • Lists, pairlists, and atomic vectors. If they have a class, they are converted with base::as.list() to allow S3 dispatch. Following this change, objects like factors can now be spliced without data loss. • S4 objects. These are converted with as(obj, "list") before splicing. • Quoted blocks of expressions, i.e. { } calls !!! disallows: • Any other objects like functions or environments, but also language objects like formula, symbols, or quosures. Quoting functions used to automatically wrap language objects in lists to make them spliceable. This behaviour is now soft-deprecated and it is no longer valid to write !!!enquo(x). Please unquote scalar objects with !! instead. • dots_list(), enexprs() and enquos() gain a .homonyms argument to control how to treat arguments with the same name. The default is to keep them. Set it to "first" or "last" to keep only the first or last occurrences. Set it to "error" to raise an informative error about the arguments with duplicated names. • enexprs() and enquos() now support .ignore_empty = "all" with named arguments as well (#414). • dots_list() gains a .preserve_empty argument. When TRUE, empty arguments are stored as missing arguments (see ?missing_arg). • dots_list(), enexprs() and enquos() gain a .check_assign argument. When TRUE, a warning is issued when a <- call is detected in .... No warning is issued if the assignment is wrapped in brackets like { a <- 1 }. The warning lets users know about a possible typo in their code (assigning instead of matching a function parameter) and requires them to be explicit that they really want to assign to a variable by wrapping in parentheses. • lapply(list(quote(foo)), list2) no longer evaluates foo (#580). ## Tidy eval • You can now unquote quosured symbols as LHS of :=. The symbol is automatically unwrapped from the quosure. • Quosure methods have been defined for common operations like ==. These methods fail with an informative error message suggesting to unquote the quosure (#478, #tidyverse/dplyr#3476). • as_data_pronoun() now accepts data masks. If the mask has multiple environments, all of these are looked up when subsetting the pronoun. Function objects stored in the mask are bypassed. • It is now possible to unquote strings in function position. This is consistent with how the R parser coerces strings to symbols. These two expressions are now equivalent: expr("foo"()) and expr((!!"foo")()). • Quosures converted to functions with as_function() now support nested quosures. • expr_deparse() (used to print quosures at the console) now escapes special characters. For instance, newlines now print as "\n" (#484). This ensures that the roundtrip parse_expr(expr_deparse(x)) is not lossy. • new_data_mask() now throws an error when bottom is not a child of top (#551). • Formulas are now evaluated in the correct environment within eval_tidy(). This fixes issues in dplyr and other tidy-evaluation interfaces. • New functions new_quosures() and as_quosures() to create or coerce to a list of quosures. This is a small S3 class that ensures two invariants on subsetting and concatenation: that each element is a quosure and that the list is always named even if only with a vector of empty strings. ## Environments • env() now treats a single unnamed argument as the parent of the new environment. Consequently, child_env() is now superfluous and is now in questioning life cycle. • New current_env() and current_fn() functions to retrieve the current environment or the function being evaluated. They are equivalent to base::environment() and base::sys.function() called without argument. • env_get() and env_get_list() gain a default argument to provide a default value for non-existing bindings. • env_poke() now returns the old value invisibly rather than the input environment. • The new function env_name() returns the name of an environment. It always adds the “namespace:” prefix to namespace names. It returns “global” instead of “.GlobalEnv” or “R_GlobalEnv”, “empty” instead of “R_EmptyEnv”. The companion env_label() is like env_name() but returns the memory address for anonymous environments. • env_parents() now returns a named list. The names are taken with env_name(). • env_parents() and env_tail() now stop at the global environment by default. This can be changed with the last argument. The empty environment is always a stopping condition so you can take the parents or the tail of an environment on the search path without changing the default. • New predicates env_binding_are_active() and env_binding_are_lazy() detect the kind of bindings in an environment. • env_binding_lock() and env_binding_unlock() allows to lock and unlock multiple bindings. The predicate env_binding_are_locked() tests if bindings are locked. • env_lock() and env_is_locked() lock an environment or test if an environment is locked. • env_print() pretty-prints environments. It shows the contents (up to 20 elements) and the properties of the environment. • is_scoped() has been soft-deprecated and renamed to is_attached(). It now supports environments in addition to search names. • env_bind_lazy() and env_bind_active() now support quosures. • env_bind_exprs() and env_bind_fns() are soft-deprecated and renamed to env_bind_lazy() and env_bind_active() for clarity and consistency. • env_bind(), env_bind_exprs(), and env_bind_fns() now return the list of old binding values (or missing arguments when there is no old value). This makes it easy to restore the original environment state: old <- env_bind(env, foo = "foo", bar = "bar") env_bind(env, !!!old) • env_bind() now supports binding missing arguments and removing bindings with zap sentinels. env_bind(env, foo = ) binds a missing argument and env_bind(env, foo = zap()) removes the foo binding. • The inherit argument of env_get() and env_get_list() has changed position. It now comes after default. • scoped_bindings() and with_bindings() can now be called without bindings. • env_clone() now recreates active bindings correctly. • env_get() now evaluates promises and active bindings since these are internal objects which should not be exposed at the R level (#554) • env_print() calls get_env() on its argument, making it easier to see the environment of closures and quosures (#567). • env_get() now supports retrieving missing arguments when inherit is FALSE. ## Calls • is_call() now accepts multiple namespaces. For instance is_call(x, "list", ns = c("", "base")) will match if x is list() or if it’s base::list(): • call_modify() has better support for ... and now treats it like a named argument. call_modify(call, ... = ) adds ... to the call and call_modify(call, ... = NULL) removes it. • call_modify() now preserves empty arguments. It is no longer necessary to use missing_arg() to add a missing argument to a call. This is possible thanks to the new .preserve_empty option of dots_list(). • call_modify() now supports removing unexisting arguments (#393) and passing multiple arguments with the same name (#398). The new .homonyms argument controls how to treat these arguments. • call_standardise() now handles primitive functions like ~ properly (#473). • call_print_type() indicates how a call is deparsed and printed at the console by R: prefix, infix, and special form. • The call_ functions such as call_modify() now correctly check that their input is the right type (#187). ## Other improvements and fixes • New function zap() returns a sentinel that instructs functions like env_bind() or call_modify() that objects are to be removed. • New function rep_named() repeats value along a character vector of names. • New function exec() is a simpler replacement to invoke() (#536). invoke() has been soft-deprecated. • Lambda functions created from formulas with as_function() are now classed. Use is_lambda() to check a function was created with the formula shorthand. • is_integerish() now supports large double values (#578). • are_na() now requires atomic vectors (#558). • The operator %@% has now a replacement version to update attributes of an object (#207). • fn_body() always returns a { block, even if the function has a single expression. For instance fn_body(function(x) do()) returns quote({ do() }). • is_string() now returns FALSE for NA_character_. • The vector predicates have been rewritten in C for performance. • The finite argument of is_integerish() is now NULL by default. Missing values are now considered as non-finite for consistency with base::is.finite(). • is_bare_integerish() and is_scalar_integerish() gain a finite argument for consistency with is_integerish(). • flatten_if() and squash_if() now handle primitive functions like base::is.list() as predicates. • is_symbol() now accepts a character vector of names to mach the symbol against. • parse_exprs() and parse_quos() now support character vectors. Note that the output may be longer than the input as each string may yield multiple expressions (such as "foo; bar"). • parse_quos() now adds the quosures class to its output. ## Lifecycle ### Soft-deprecated functions and arguments rlang 0.3.0 introduces a new warning mechanism for soft-deprecated functions and arguments. A warning is issued, but only under one of these circumstances: • rlang has been attached with a library() call. • The deprecated function has been called from the global environment. In addition, deprecation warnings appear only once per session in order to not be disruptive. Deprecation warnings shouldn’t make R CMD check fail for packages using testthat. However, expect_silent() can transform the warning to a hard failure. #### tidyeval • .data[[foo]] is now an unquote operator. This guarantees that foo is evaluated in the context rather than the data mask and makes it easier to treat .data[["bar"]] the same way as a symbol. For instance, this will help ensuring that group_by(df, .data[["name"]]) and group_by(df, name) produce the same column name. • Automatic naming of expressions now uses a new deparser (still unexported) instead of quo_text(). Following this change, automatic naming is now compatible with all object types (via pillar::type_sum() if available), prevents multi-line names, and ensures name and .data[["name"]] are given the same default name. • Supplying a name with !!! calls is soft-deprecated. This name is ignored because only the names of the spliced vector are applied. • Quosure lists returned by quos() and enquos() now have “list-of” behaviour: the types of new elements are checked when adding objects to the list. Consequently, assigning non-quosure objects to quosure lists is now soft-deprecated. Please coerce to a bare list with as.list() beforehand. • as_quosure() now requires an explicit environment for symbols and calls. This should typically be the environment in which the expression was created. • names() and length() methods for data pronouns are deprecated. It is no longer valid to write names(.data) or length(.data). • Using as.character() on quosures is soft-deprecated (#523). #### Miscellaneous • Using get_env() without supplying an environment is now soft-deprecated. Please use current_env() to retrieve the current environment. • The frame and stack API is soft-deprecated. Some of the functionality has been replaced by trace_back(). • The new_vector_along() family is soft-deprecated because these functions are longer to type than the equivalent rep_along() or rep_named() calls without added clarity. • Passing environment wrappers like formulas or functions to env_ functions is now soft-deprecated. This internal genericity was causing confusion (see issue #427). You should now extract the environment separately before calling these functions. This change concerns env_depth(), env_poke_parent(), env_parent<-, env_tail(), set_env(), env_clone(), env_inherits(), env_bind(), scoped_bindings(), with_bindings(), env_poke(), env_has(), env_get(), env_names(), env_bind_exprs() and env_bind_fns(). • cnd_signal() now always installs a muffling restart for non-critical conditions. Consequently the .mufflable argument has been soft-deprecated and no longer has any effect. ### Deprecated functions and arguments Deprecated functions and arguments issue a warning inconditionally, but only once per session. • Calling UQ() and UQS() with the rlang namespace qualifier is deprecated as of rlang 0.3.0. Just use the unqualified forms instead: # Bad rlang::expr(mean(rlang::UQ(var) * 100)) # Ok rlang::expr(mean(UQ(var) * 100)) # Good rlang::expr(mean(!!var * 100)) Although soft-deprecated since rlang 0.2.0, UQ() and UQS() can still be used for now. • The call argument of abort() and condition constructors is now deprecated in favour of storing full backtraces. • The .standardise argument of call_modify() is deprecated. Please use call_standardise() beforehand. • The sentinel argument of env_tail() has been deprecated and renamed to last. ### Defunct functions and arguments Defunct functions and arguments throw an error when used. • as_dictionary() is now defunct. • The experimental function rst_muffle() is now defunct. Please use cnd_muffle() instead. Unlike its predecessor, cnd_muffle() is not generic. It is marked as a calling handler and thus can be passed directly to with_handlers() to muffle specific conditions (such as specific subclasses of warnings). • cnd_inform(), cnd_warn() and cnd_abort() are retired and defunct. The old cnd_message(), cnd_warning(), cnd_error() and new_cnd() constructors deprecated in rlang 0.2.0 are now defunct. • Modifying a condition with cnd_signal() is defunct. In addition, creating a condition with cnd_signal() is soft-deprecated, please use the new function [signal()] instead. • inplace() has been renamed to calling() to follow base R terminology more closely. ### Functions and arguments in the questioning stage We are no longer convinced these functions are the right approach but we do not have a precise alternative yet. • The functions from the restart API are now in the questioning lifecycle stage. It is not clear yet whether we want to recommend restarts as a style of programming in R. • prepend() and modify() are in the questioning stage, as well as as_logical(), as_character(), etc. We are still figuring out what vector tools belong in rlang. • flatten(), squash() and their atomic variants are now in the questioning lifecycle stage. They have slightly different semantics than the flattening functions in purrr and we are currently rethinking our approach to flattening with the new typing facilities of the vctrs package. # rlang 0.2.2 2018-08-16 This is a maintenance release that fixes several garbage collection protection issues. # rlang 0.2.1 2018-05-30 This is a maintenance release that fixes several tidy evaluation issues. • Functions with tidy dots support now allow splicing atomic vectors. • Quosures no longer capture the current srcref. • Formulas are now evaluated in the correct environment by eval_tidy(). This fixes issues in dplyr and other tidy-evaluation interfaces. # rlang 0.2.0 2018-02-20 This release of rlang is mostly an effort at polishing the tidy evaluation framework. All tidy eval functions and operators have been rewritten in C in order to improve performance. Capture of expression, quasiquotation, and evaluation of quosures are now vastly faster. On the UI side, many of the inconveniences that affected the first release of rlang have been solved: • The !! operator now has the precedence of unary + and - which allows a much more natural syntax: !!a > b only unquotes a rather than the whole a > b expression. • enquo() works in magrittr pipes: mtcars %>% select(!!enquo(var)). • enquos() is a variant of quos() that has a more natural interface for capturing multiple arguments and .... See the first section below for a complete list of changes to the tidy evaluation framework. This release also polishes the rlang API. Many functions have been renamed as we get a better feel for the consistency and clarity of the API. Note that rlang as a whole is still maturing and some functions are even experimental. In order to make things clearer for users of rlang, we have started to develop a set of conventions to document the current stability of each function. You will now find “lifecycle” sections in documentation topics. In addition we have gathered all lifecycle information in the ?rlang::lifecycle help page. Please only use functions marked as stable in your projects unless you are prepared to deal with occasional backward incompatible updates. ## Tidy evaluation • The backend for quos(), exprs(), list2(), dots_list(), etc is now written in C. This greatly improve the performance of dots capture, especially with the splicing operator !!! which now scales much better (you’ll see a 1000x performance gain in some cases). The unquoting algorithm has also been improved which makes enexpr() and enquo() more efficient as well. • The tidy eval !! operator now binds tightly. You no longer have to wrap it in parentheses, i.e. !!x > y will only unquote x. Technically the !! operator has the same precedence as unary - and +. This means that !!a:b and !!a + b are equivalent to (!!a):b and (!!a) + b. On the other hand !!a^b and !!a$b are equivalent to!!(a^b) and !!(a\$b).

• The print method for quosures has been greatly improved. Quosures no longer appear as formulas but as expressions prefixed with ^; quosures are colourised according to their environment; unquoted objects are displayed between angular brackets instead of code (i.e. an unquoted integer vector is shown as <int: 1, 2> rather than 1:2); unquoted S3 objects are displayed using pillar::type_sum() if available.

• New enquos() function to capture arguments. It treats ... the same way as quos() but can also capture named arguments just like enquo(), i.e. one level up. By comparison quos(arg) only captures the name arg rather than the expression supplied to the arg argument.

In addition, enexprs() is like enquos() but like exprs() it returns bare expressions. And ensyms() expects strings or symbols.

• It is now possible to use enquo() within a magrittr pipe:

select_one <- function(df, var) {
df %>% dplyr::select(!!enquo(var))
}

Technically, this is because enquo() now also captures arguments in parents of the current environment rather than just in the current environment. The flip side of this increased flexibility is that if you made a typo in the name of the variable you want to capture, and if an object of that name exists anywhere in the parent contexts, you will capture that object rather than getting an error.

• quo_expr() has been renamed to quo_squash() in order to better reflect that it is a lossy operation that flattens all nested quosures.

• !!! now accepts any kind of objects for consistency. Scalar types are treated as vectors of length 1. Previously only symbolic objects like symbols and calls were treated as such.

• ensym() is a new variant of enexpr() that expects a symbol or a string and always returns a symbol. If a complex expression is supplied it fails with an error.

• exprs() and quos() gain a .unquote_names arguments to switch off interpretation of := as a name operator. This should be useful for programming on the language targetting APIs such as data.table.

• exprs() gains a .named option to auto-label its arguments (#267).

• Functions taking dots by value rather than by expression (e.g. regular functions, not quoting functions) have a more restricted set of unquoting operations. They only support := and !!!, and only at top-level. I.e. dots_list(!!! x) is valid but not dots_list(nested_call(!!! x)) (#217).

• Functions taking dots with list2() or dots_list() now support splicing of NULL values. !!! NULL is equivalent to !!! list() (#242).

• Capture operators now support evaluated arguments. Capturing a forced or evaluated argument is exactly the same as unquoting that argument: the actual object (even if a vector) is inlined in the expression. Capturing a forced argument occurs when you use enquo(), enexpr(), etc too late. It also happens when your quoting function is supplied to lapply() or when you try to quote the first argument of an S3 method (which is necessarily evaluated in order to detect which class to dispatch to). (#295, #300).

• Parentheses around !! are automatically removed. This makes the generated expression call cleaner: (!! sym("name"))(arg). Note that removing the parentheses will never affect the actual precedence within the expression as the parentheses are only useful when parsing code as text. The parentheses will also be added by R when printing code if needed (#296).

• Quasiquotation now supports !! and !!! as functional forms:

expr(!!(var))
quo(call(!!!(var)))

This is consistent with the way native R operators parses to function calls. These new functional forms are to be preferred to UQ() and UQS(). We are now questioning the latter and might deprecate them in a future release.

• The quasiquotation parser now gives meaningful errors in corner cases to help you figure out what is wrong.

• New getters and setters for quosures: quo_get_expr(), quo_get_env(), quo_set_expr(), and quo_set_env(). Compared to get_expr() etc, these accessors only work on quosures and are slightly more efficient.

• quo_is_symbol() and quo_is_call() now take the same set of arguments as is_symbol() and is_call().

• enquo() and enexpr() now deal with default values correctly (#201).

• Splicing a list no longer mutates it (#280).

## Conditions

• The new functions cnd_warn() and cnd_inform() transform conditions to warnings or messages before signalling them.

• cnd_signal() now returns invisibly.

• cnd_signal() and cnd_abort() now accept character vectors to create typed conditions with several S3 subclasses.

• is_condition() is now properly exported.

• Condition signallers such as cnd_signal() and abort() now accept a call depth as call arguments. This allows plucking a call from further up the call stack (#30).

• New helper catch_cnd(). This is a small wrapper around tryCatch() that captures and returns any signalled condition. It returns NULL if none was signalled.

• cnd_abort() now adds the correct S3 classes for error conditions. This fixes error catching, for instance by testthat::expect_error().

## Environments

• env_get_list() retrieves muliple bindings from an environment into a named list.

• with_bindings() and scoped_bindings() establish temporary bindings in an environment.

• is_namespace() is a snake case wrapper around isNamespace().

## Various features

• New functions inherits_any(), inherits_all(), and inherits_only(). They allow testing for inheritance from multiple classes. The _any variant is equivalent to base::inherits() but is more explicit about its behaviour. inherits_all() checks that all classes are present in order and inherits_only() checks that the class vectors are identical.

• New fn_fmls<- and fn_fmls_names<- setters.

• New function experimental function chr_unserialise_unicode() for turning characters serialised to unicode point form (e.g. <U+xxxx>) to UTF-8. In addition, as_utf8_character() now translates those as well. (@krlmlr)

• expr_label() now supports quoted function definition calls (#275).

• call_modify() and call_standardise() gain an argument to specify an environment. The call definition is looked up in that environment when the call to modify or standardise is not wrapped in a quosure.

• is_symbol() gains a name argument to check that that the symbol name matches a string (#287).

• New rlang_box class. Its purpose is similar to the AsIs class from base::I(), i.e. it protects a value temporarily. However it does so by wrapping the value in a scalar list. Use new_box() to create a boxed value, is_box() to test for a boxed value, and unbox() to unbox it. new_box() and is_box() accept optional subclass.

• The vector constructors such as new_integer(), new_double_along() etc gain a names argument. In the case of the _along family it defaults to the names of the input vector.

## Bugfixes

• When nested quosures are evaluated with eval_tidy(), the .env pronoun now correctly refers to the current quosure under evaluation (#174). Previously it would always refer to the environment of the outermost quosure.

• as_pairlist() (part of the experimental API) now supports NULL and objects of type pairlist (#397).

• Fixed a performance bug in set_names() that caused a full copy of the vector names (@jimhester, #366).

## API changes

The rlang API is maturing and still in flux. However we have made an effort to better communicate what parts are stable. We will not introduce breaking changes for stable functions unless the payoff for the change is worth the trouble. See ?rlang::lifecycle for the lifecycle status of exported functions.

• The particle “lang” has been renamed to “call”:

• lang() has been renamed to call2().
• new_language() has ben renamed to new_call().
• is_lang() has been renamed to is_call(). We haven’t replaced the is_unary_lang() and is_binary_lang() because they are redundant with the n argument of is_call().
• All call accessors such as lang_fn(), lang_name(), lang_args() etc are soft-deprecated and renamed with call_ prefix.

In rlang 0.1 calls were called “language” objects in order to follow the R type nomenclature as returned by base::typeof(). We wanted to avoid adding to the confusion between S modes and R types. With hindsight we find it is better to use more meaningful type names.

• We now use the term “data mask” instead of “overscope”. We think data mask is a more natural name in the context of R. We say that that objects from user data mask objects in the current environment. This makes reference to object masking in the search path which is due to the same mechanism (in technical terms, lexical scoping with hierarchically nested environments).

Following this new terminology, the new functions as_data_mask() and new_data_mask() replace as_overscope() and new_overscope(). as_data_mask() has also a more consistent interface. These functions are only meant for developers of tidy evaluation interfaces.

• We no longer require a data mask (previously called overscope) to be cleaned up after evaluation. overscope_clean() is thus soft-deprecated without replacement.

### Breaking changes

• !! now binds tightly in order to match intuitive parsing of tidy eval code, e.g. !! x > y is now equivalent to (!! x) > y. A corollary of this new syntax is that you now have to be explicit when you want to unquote the whole expression on the right of !!. For instance you have to explicitly write !! (x > y) to unquote x > y rather than just x.

• UQ(), UQS() and := now issue an error when called directly. The previous definitions caused surprising results when the operators were invoked in wrong places (i.e. not in quasiquoted arguments).

• The prefix form !!() is now an alias to !! rather than UQE(). This makes it more in line with regular R syntax where operators are parsed as regular calls, e.g. a + b is parsed as +(a, b) and both forms are completely equivalent. Also the prefix form !!!() is now equivalent to !!!.

• UQE() is now deprecated in order to simplify the syntax of quasiquotation. Please use !! get_expr(x) instead.

• expr_interp() now returns a formula instead of a quosure when supplied a formula.

• is_quosureish() and as_quosureish() are deprecated. These functions assumed that quosures are formulas but that is only an implementation detail.

• new_cnd() is now cnd() for consistency with other constructors. Also, cnd_error(), cnd_warning() and cnd_message() are now error_cnd(), warning_cnd() and message_cnd() to follow our naming scheme according to which the type of output is a suffix rather than a prefix.

• is_node() now returns TRUE for calls as well and is_pairlist() does not return TRUE for NULL objects. Use is_node_list() to determine whether an object either of type pairlist or NULL. Note that all these functions are still experimental.

• set_names() no longer automatically splices lists of character vectors as we are moving away from automatic splicing semantics.

### Upcoming breaking changes

• Calling the functional forms of unquote operators with the rlang namespace qualifier is soft-deprecated. UQ() and UQS() are not function calls so it does not make sense to namespace them. Supporting namespace qualifiers complicates the implementation of unquotation and is misleading as to the nature of unquoting (which are syntactic operators at quotation-time rather than function calls at evaluation-time).

• We are now questioning UQ() and UQS() as functional forms of !!. If !! and !!! were native R operators, they would parse to the functional calls !!() and !!!(). This is now the preferred way to unquote with a function call rather than with the operators. We haven’t decided yet whether we will deprecate UQ() and UQS() in the future. In any case we recommend using the new functional forms.

• parse_quosure() and parse_quosures() are soft-deprecated in favour of parse_quo() and parse_quos(). These new names are consistent with the rule that abbreviated suffixes indicate the return type of a function. In addition the new functions require their callers to explicitly supply an environment for the quosures.

• Using f_rhs() and f_env() on quosures is soft-deprecated. The fact that quosures are formulas is an implementation detail that might change in the future. Please use quo_get_expr() and quo_get_env() instead.

• quo_expr() is soft-deprecated in favour of quo_squash(). quo_expr() was a misnomer because it implied that it was a mere expression acccessor for quosures whereas it was really a lossy operation that squashed all nested quosures.

• With the renaming of the lang particle to call, all these functions are soft-deprecated: lang(), is_lang(), lang_fn(), lang_name(), lang_args().

In addition, lang_head() and lang_tail() are soft-deprecated without replacement because these are low level accessors that are rarely needed.

• as_overscope() is soft-deprecated in favour of as_data_mask().

• The node setters were renamed from mut_node_ prefix to node_poke_. This change follows a new naming convention in rlang where mutation is referred to as “poking”.

• splice() is now in questioning stage as it is not needed given the !!! operator works in functions taking dots with dots_list().

• lgl_len(), int_len() etc have been soft-deprecated and renamed with new_ prefix, e.g. new_logical() and new_integer(). This is for consistency with other non-variadic object constructors.

• ll() is now an alias to list2(). This is consistent with the new call2() constructor for calls. list2() and call2() are versions of list() and call() that support splicing of lists with !!!. ll() remains around as a shorthand for users who like its conciseness.

• Automatic splicing of lists in vector constructors (e.g. lgl(), chr(), etc) is now soft-deprecated. Please be explicit with the splicing operator !!!.

# rlang 0.1.6 2017-12-21

• This is a maintenance release in anticipation of a forthcoming change to R’s C API (use MARK_NOT_MUTABLE() instead of SET_NAMED()).

• New function is_reference() to check whether two objects are one and the same.

# rlang 0.1.4 2017-11-05

• eval_tidy() no longer maps over lists but returns them literally. This behaviour is an overlook from past refactorings and was never documented.

# rlang 0.1.2 2017-08-09

This hotfix release makes rlang compatible with the R 3.1 branch.

# rlang 0.1.1 2017-05-18

This release includes two important fixes for tidy evaluation:

• Bare formulas are now evaluated in the correct environment in tidyeval functions.

• enquo() now works properly within compiled functions. Before this release, constants optimised by the bytecode compiler couldn’t be enquoted.

## New functions:

• The new_environment() constructor creates a child of the empty environment and takes an optional named list of data to populate it. Compared to env() and child_env(), it is meant to create environments as data structures rather than as part of a scope hierarchy.

• The new_call() constructor creates calls out of a callable object (a function or an expression) and a pairlist of arguments. It is useful to avoid costly internal coercions between lists and pairlists of arguments.

## UI improvements:

• env_child()’s first argument is now .parent instead of parent.

• mut_ setters like mut_attrs() and environment helpers like env_bind() and env_unbind() now return their (modified) input invisibly. This follows the tidyverse convention that functions called primarily for their side effects should return their input invisibly.

• is_pairlist() now returns TRUE for NULL. We added is_node() to test for actual pairlist nodes. In other words, is_pairlist() tests for the data structure while is_node() tests for the type.

## Bugfixes:

• env() and env_child() can now get arguments whose names start with .. Prior to this fix, these arguments were partial-matching on env_bind()’s .env argument.

• The internal replace_na() symbol was renamed to avoid a collision with an exported function in tidyverse. This solves an issue occurring in old versions of R prior to 3.3.2 (#133).

Initial release.


text:
Question: Explain overhauling and self locking of screw.
0

Subject: Machine Design -I

Difficulty: Medium

md1(66) • 4.4k views
 modified 10 months ago by written 14 months ago by kiran.9870 • 10
0

Over hauling:

• The torque required to lower the load can be given by the equation,

$T=\frac{Wd_m}{2}tan(\phi-\alpha)$

• It can be seen when $\phi\lt\alpha$ the torque required to lower the load is negative.

• It indicates a condition that no force is required to lower the load. The load itself will begin to turn the screw and descend down, unless a restraining torque is applied.

• The condition is called overhauling of the screw. This condition is also called back driving of screw.

Self-locking:

• When $\phi$ is greater than or equal to $\alpha$, a positive torque is required to lower the load.
• Under this condition, the load will not turn the screw and will not descend on its own unless an effort P is applied.
• Screw will be self-locking if the co-efficient of friction is equal to or greater than the tangent of the helix angle, the screw is said to be self-locking.

Condition for:

Overhauling $\phi \lt \alpha$
Self-locking $\phi \ge \alpha$


text:
# factor!als

Algebra Level 3

$$w$$ , $$x$$ ,$$y$$ , $$z$$ is a positive integer , and

$$w!=x!+y!+z!$$

find $$wxyz$$

×