The $p_\mathrm{T}$-differential production cross sections of prompt and non-prompt (produced in beauty-hadron decays) D mesons were measured by the ALICE experiment at midrapidity ($|y|<0.5$) in proton--proton collisions at $\sqrt{s}=5.02~\mathrm{TeV}$. The data sample used in the analysis corresponds to an integrated luminosity of $(19.3\pm0.4)~\mathrm{nb^{-1}}$. D mesons were reconstructed from their decays $\mathrm{D^0 \to K^-\pi^+}$, $\mathrm{D^+\to K^-\pi^+\pi^+}$, and $\mathrm{D_s^+\to \phi\pi^+\to K^-K^+\pi^+}$ and their charge conjugates. Compared to previous measurements in the same rapidity region, the cross sections of prompt $\mathrm{D^+}$ and $\mathrm{D_s^+}$ mesons have an extended $p_\mathrm{T}$ coverage and total uncertainties reduced by a factor ranging from 1.05 to 1.6, depending on $p_\mathrm{T}$, allowing for a more precise determination of their $p_\mathrm{T}$-integrated cross sections. The results are well described by perturbative QCD calculations. The fragmentation fraction of heavy quarks to strange mesons divided by the one to non-strange mesons, $f_\mathrm{s}/(f_\mathrm{u}+f_\mathrm{d})$, is compatible for charm and beauty quarks and with previous measurements at different centre-of-mass energies and collision systems. The $\mathrm{b\overline{b}}$ production cross section per rapidity unit at midrapidity, estimated from non-prompt D-meson measurements, is $\mathrm{d}\sigma_\mathrm{b\overline{b}}/\mathrm{d} y|_\mathrm{|y|<0.5} = 34.5 \pm 2.4 (\mathrm{stat.}) ^{+4.7}_{-2.9} (\mathrm{tot. syst.})~\mu\mathrm{b}$. It is compatible with previous measurements at the same centre-of-mass energy and with the cross section predicted by perturbative QCD calculations.
$p_\mathrm{T}$-differential production cross section of non-prompt $\mathrm{D^0}$ mesons in pp collision at $\sqrt{s}=5.02~\mathrm{TeV}$ in the rapidity interval $|y|<0.5$. Branching ratio of $\mathrm{D^0 \to K^-\pi^+}$: 0.0395
$p_\mathrm{T}$-differential production cross section of non-prompt $\mathrm{D^+}$ mesons in pp collision at $\sqrt{s}=5.02~\mathrm{TeV}$ in the rapidity interval $|y|<0.5$. Branching ratio of $\mathrm{D^+\to K^-\pi^+\pi^+}$: 0.0938
$p_\mathrm{T}$-differential production cross section of non-prompt $\mathrm{D_{s}^{+}}$ mesons in pp collision at $\sqrt{s}=5.02~\mathrm{TeV}$ in the rapidity interval $|y|<0.5$. Branching ratio of $\mathrm{D_s^+\to \phi\pi^+\to K^-K^+\pi^+}$: 0.0224
The prompt production of the charm baryon $\rm \Lambda_{c}^{+}$ and the $\rm \Lambda_{c}^{+}/\mathrm {D^0}$ production ratios were measured at midrapidity with the ALICE detector in pp and p-Pb collisions at $\sqrt{s_\mathrm{NN}} = 5.02$TeV. These new measurements show a clear decrease of the $\rm \Lambda_{c}^{+}/\mathrm {D^0}$ ratio with increasing transverse momentum ($p_{\rm T}$) in both collision systems in the range $2
Prompt $\Lambda_{\rm {c}}^{+}$ baryon $p_{\rm {T}}$-differential cross section in pp collisions at $\sqrt{s} = 5.02$ TeV in the rapidity interval $|y|<0.5$.
Prompt $\Lambda_{\rm {c}}^{+}$ baryon $p_{\rm {T}}$-differential cross section in p-Pb collisions at $\sqrt{s_{\rm {NN}}} = 5.02$ TeV in the rapidity interval $-0.96 \lt y \lt 0.04$.
The nuclear modification factor $R_\mathrm{pPb}$ of prompt $\Lambda_{\rm {c}}^{+}$ baryons in p-Pb collisions at $\sqrt{s_{\rm {NN}}} = 5.02$ TeV in the rapidity interval $ -0.96\lt y \lt 0.04$.