Let's analyze the sentence fragments:
1. Start with the main subject and action:
- "Automation in manufacturing processes has" (R) is the main subject and action, so it naturally starts the sentence.
2. Describe the effects of the action:
- "Not only improved productivity" (P) follows, indicating one of the effects of automation.
3. Mention the additional effect:
- "But also reduced the margin of human error" (Q) adds another effect of automation, following the previous one.
4. Give the time frame:
- "Over the past few decades" (S) provides the time frame during which these changes have occurred, making it a fitting conclusion.
Thus, the correct sequence is: R, P, S, Q.