Your first attempt is the correct answer if that's all you're trying to do. nlme() works out the between and within components, you don't need to specify them.
The problem you're running into isn't because you don't know how to specify the model, it's because repeated measures ANOVA and mixed effects are not the same thing. Sometimes the results from the ANOVA and mixed effects model will match. This is especially the case when you aggregate your data like you would for an ANOVA and calculate both from that. But generally, when done correctly, while the conclusions may be similar the results are almost never the same. Your example data aren't like real repeated measures where you often have replications of each measure within S. When you do an ANOVA typically you aggregate across those replications to get an estimate of the effect for each subject. In mixed effects modelling you do no such thing. You work with the raw data. When you do that you'll find that the results are never the same between ANOVA and lme().