Recently it was shown that there is a unique R 4 symmetry for the MSSM which allows the Yukawa couplings and dimension five neutrino mass operator, forbids the µ term and commutes with SO(10). This R 4 symmetry contains matter parity as a subgroup and forbids dimension four and five proton decay operators. We show how to construct string vacua with discrete R symmetries in general and this symmetry in particular, and present an explicit example which exhibits the exact MSSM spectrum, the R 4 symmetry as well as other desired features such as gauge-top unification. We introduce the Hilbert basis method for determining all D-flat configurations and efficient algorithms for identifying field configurations with a desired residual symmetry. These methods are used in an explicit example, in which we describe in detail how to construct a supersymmetric vacuum configuration with the phenomenologically attractive R 4 symmetry. At the perturbative level, this is a supersymmetric Minkowski vacuum in which almost all singlet fields (moduli) are fixed.