How many pigs can I keep in a single pen at once?

Up to four animals of one kind fit in a pen. To get the second one you need to go to market repeatedly until you find a matching pair.

Once there are at least two animals in a pen, new ones will spawn autonomously.

Reference: source code