Preheat your oven to 350°F (175°C). Line a muffin tin with cupcake liners.
In a large mixing bowl, whisk together the flour, granulated sugar, brown sugar, baking soda, baking powder, salt, cinnamon, and nutmeg.
In another bowl, mix the oil and eggs until well combined.
Gradually add the wet ingredients to the dry mixture and stir with a rubber spatula until just combined. Avoid overmixing.
Fold in the grated carrots, crushed pineapple, and walnuts if using.
Pour the batter into the prepared cupcake liners, filling each about ⅔ full.
Bake in the preheated oven for 18-20 minutes, or until a toothpick inserted into the center comes out clean.
Allow the cupcakes to cool in the pan for 5 minutes, then transfer to a wire rack to cool completely.
While the cupcakes are cooling, prepare the frosting. In a bowl, beat the cream cheese and butter together until smooth. Gradually add the powdered sugar and vanilla extract, mixing until fluffy.
Once the cupcakes are completely cooled, pipe or spread the cream cheese frosting on top.