I'm trying to show that every closed subscheme $Y$ of an affine scheme $X = \operatorname{Spec}(R)$ is isomorphic to $\operatorname{Spec}(R/I)$ for some ideal $I$ of $R$. I try to show that there exists an isomorphism of schemes $Y \to \operatorname{Spec}(R/I)$ where $I = \ker\big( R \to \mathcal{O}_Y(Y)\big)$.
I already managed to show that the map on the underlying topological spaces is a homeomorphism but I'm having trouble proving that the map $\mathcal{O}_{\operatorname{Spec}(R/I)} \to \mathcal{O}_Y$ is a bijection. I know that by definition it is surjective but I don't really know how I can show injectivity.