In this paper we look at the pinning of a directed polymer by a one-dimensional linear interface carrying random charges. There are two phases, localized and delocalized, depending on the inverse temperature and on the disorder bias. Using quenched and annealed large deviation principles for the empirical process of words drawn from a random letter sequence according to a random renewal process (Birkner, Greven and den Hollander ), we derive variational formulas for the quenched, respectively, annealed critical curve separating the two phases. These variational formulas are used to obtain a necessary and sufficient criterion, stated in terms of relative entropies, for the two critical curves to be different at a given inverse temperature, a property referred to as relevance of the disorder. This criterion in turn is used to show that the regimes of relevant and irrelevant disorder are separated by a unique inverse critical temperature. Subsequently, upper and lower bounds are derived for the inverse critical temperature, from which sufficient conditions under which it is strictly positive, respectively, finite are obtained. The former condition is believed to be necessary as well, a problem that we will address in a forthcoming paper. Random pinning has been studied extensively in the literature. The present paper opens up a window with a variational view. Our variational formulas for the quenched and the annealed critical curve are new and provide valuable insight into the nature of the phase transition. Our results on the inverse critical temperature drawn from these variational formulas are not new, but they offer an alternative approach that is flexible enough to be extended to other models of random polymers with disorder.