Preheat oven to 350°F (175°C).
In a large bowl, mix sugar and oil. Add eggs one at a time, beating well after each addition.
In another bowl, combine flour, baking powder, baking soda, salt, cinnamon, and nutmeg.
Gradually add dry ingredients to wet ingredients, mixing until just combined.
Fold in grated carrots and walnuts if using.
Divide batter evenly among cupcake liners in a muffin tin.
Bake for 20 minutes or until a toothpick inserted into the center comes out clean.
Let cool completely before frosting if desired.