Early observations of comet C/2016 R2 (PanSTARRS) have shown that the composition of this comet is very peculiar. We obtained high resolution spectra of the comet in February when it was at 2.8 au from the Sun. We used the UVES spectrograph of the ESO VLT, complemented with narrow-band images obtained with the TRAPPIST telescopes. We detect strong emissions from the ions $mathrm{N_2^+}$ and $mathrm{CO^+}$, but also $mathrm{CO_2^+}$, emission from the CH radical, and much fainter emissions of the CN, $mathrm{C_2}$, and $mathrm{C_3}$ radicals which were not detected in previous observations of this comet. We do not detect OH or $mathrm{H_2O^+}$, and derive an upper limit of the $mathrm{H_2O^+/CO^+}$ ratio of 0.4, implying that the comet has a low water abundance. We measure a $mathrm{N_2^+/CO^+}$ ratio of $0.06pm0.01$. The non-detection of $mathrm{NH_2}$ indicates that most of the nitrogen content of the comet lies within $mathrm{N_2}$. Together with the high $mathrm{N_2^+/CO^+}$ ratio, this could indicate a low formation temperature of the comet, or that the comet is a fragment of a large differentiated Kuiper Belt object. The $mathrm{CO_2^+/CO^+}$ ratio is $1.1pm0.3$. We do not detect $mathrm{^{14}N^{15}N^+}$ lines, and can only put a lower limit on the $mathrm{^{14}N/^{15}N}$ ratio measured from $mathrm{N_2^+}$ of about 100, compatible with measurements of the same isotopic ratio for $mathrm{NH_2}$ and CN in other comets. Finally, in addition to the [OI] and [CI] forbidden lines, we detect for the first time the forbidden nitrogen lines [NI] doublet at 519.79 and 520.04 nm in the coma of a comet.