emmeans: command emmeans() or contrast(), whats the difference? I hope somebody is available to help a desperate rookie..
I fitted a glmer with a Poisson distribution and log link, including main effects and several interactions, an offset variable and a random effect. Something like this:
model1 <- glmer(count ~ A + B + C + A*B + offset(log(X)) + ( 1 | D), data = workmap, family = poisson(link = "log"))
A, B and C are all factors with two levels.
My Prof generated "contrasts of marginal linear predictions" in Stata to, for example, look at the contrasts provided by A@B, or just simply A. I now want to do the same but in R by making use of the emmeans package.
First: should I use emmeans() or contrast() command? What is the difference?
I did the following: emm <- emmeans(model1, pairwise ~ A | B)
Was that the right thing to do or should I have used the contrast() command?

Classically in statistics

a contrast is a linear combination of variables (parameters or statistics) whose coefficients add up to zero, allowing comparison of different treatments.

In practice, the term has often been expanded to include any linear combination whether or not the coefficients of the contrast add up to zero, as noted in the emmeans vignette on contrasts.
If you have the coefficient estimates and their covariance matrix, you can use the formulas for the variance of a linear combination to calculate any desired contrast (in that extended sense) and its standard error yourself. If you're just learning, it might make sense to try that yourself on some simple cases.
The emmeans package provides some very useful, widely applicable tools to make such calculations easier. It does that by first constructing what's called a "reference grid" for the underlying model, as explained in a vignette. The model is based on the data directly while the reference grid is based on the model of the data.
So the first step in using any of the emmeans tools is to set up the reference grid. That's done conveniently as part of a call to the emmeans() function. The way you called the function, however:
emm <- emmeans(model1, pairwise ~ A | B)

also generated the indicated set of pairwise contrasts based on the reference grid it generated. If you look at your emm object you will find that it is a list of 2 emmGrid objects, one for the specified aspects of the original model and a second representing the specified contrasts.
In emmeans the contrast() function only works on an emmGrid object. That allows you to evaluate additional contrasts beyond what you first considered in your call to emmeans() without having to rebuild the grid for the original model. It also allows you to work with derived grids. For example, yesterday I did further contrasts on a grid representing an initial set of contrasts.
That's not the way that a contrast() function works in all software, however. In the rms package the contrast() function works directly on models. And those type of contrast() functions are different from the contrasts() function in the standard R stats package that reports or specifies how a particular categorical variable will be coded in a model in the first place.
So read very carefully to see how the word "contrast" and any associated functions are being used in a given context.
