I was told that a canister of compressed air gets cold because of the ideal gas law, you are lowering the pressure and since the density of air is the same, the temperature of the can gets cold. I was trying to see this mathematically and I became confused. Can someone please help me with the intuition.
The ideal gas law equation is $PV=nRT$ where R is $8.314 \frac{J}{mol \cdot K}$ if you convert from moles to kg, you get:
$$ R = 8.314 \frac{J}{mol \cdot K} \times \frac{1 mol}{0.02897 kg} = \frac{287 J }{kg \cdot K} $$
So we can change $nR$ where n is number of moles and $R$ is joules per mole-kelvin to $mR$ where m is mass and $R$ is Joules per kg-kelvin because $nR = \text{ joules } = mR$.
This gives $PV=mRT$
Assuming $m$ is the mass of 1 liter of air, and V is 1, then we have $P=\rho RT$, where $\rho$ is density.
I'm told this equation would explain why the can of air gets cold, since the density of air does not change. But this equation was formed under the assumption of a constant mass of air. In the compressed air example, the mass of air in the can is decreasing, and the volume stays the same. So I don't think we can describe the air can with $P = \rho R T$ I think it must be described with $PV = mRT$, and if the mass goes down, the pressure can go down, and the can does not have to get cold.
Am I correct that the $P=\rho RT$ equation does not hold if the mass inside the can is changing?
I saw another stack answer, Why does the gas get cold when I spray it?, but it is insanely complicated and doesn't mention the ideal gas law. I'm mostly trying to figure out why the ideal gas law does or does not answer the question, I can't begin to understand what they are saying in that other answer.