Why is the structure sheaf for the spectrum of a ring defined locally? I am currently learning for a course in algebraic geometry and wonder about the definition of the structure sheaf of the prime spectrum of a ring.
Assume, that we have an open set $U$ in $X := Spec(R)$. Then there is an ideal $I$ in $R$, such that $U = Spec(R) - V(I)$ where $V(I)$ denotes the vanishing set of that ideal.
So it would be legal to define functions on $U$ of the form $\frac{f}{g}$, where $f \in R$, $g \in I$, because you do not "divide by zero".
So I would expect $\mathcal{O}_X(U)$ to be something like $I^{-1}R$, but there are a few things weird with that. First of all "localization at an ideal" seems to be something very off, as I have never seen that.
Secondly the definition of the structure sheaf requires the functions only to be locally given by quotients. I suspect that requiring a global presentation as a quotient would contradict a sheaf axiom, probably the gluing together, but try as I might, I could not come up with an example. So my two questions are the following:
1.) Why is localization at an ideal weird?
2.) Could you give an example of an affine scheme, where the gluing together of some globally presented functions does not have a global presentation?
 A: As remarked by @user113969 you do not want to invert what is in $I$, you want to invert what is not in $I$.  You have seen localization at prime ideals $p$, which means inverting everything that is not in $p$.  In schemes, that amounts to taking the intersection of all open sets around $p$.
The standard approach is to first define the distinguished open subsets of $Spec(R)$, which are the complements to closed subsets $V(g)\subseteq Spec(R)$.  Think of  $V(g)$ as the zero locus of a single function $g\in R$ (albeit in general $R$ is not really a ring of functions).  Intuitively the open complement to this closed set is the subset of $Spec(R)$ where $g\neq 0$, and precisely we get it by insisting $g$ has an inverse $\frac{1}{g}$.  I take it you know the ring $R_g=(g)^{-1}R$ which is $R$ plus a formal inverse to $g$. 
Then a general open subset is any union of the distinguished opens.  Notice this already allows the possibility that some point in the union would have been excluded by inverting one $g\in R$ but is not excluded by inverting a different $h\in R$.
To see the issue of question 2 geometrically think $R=\mathbb{C}[x_1,x_2,x_3,x_4]/(x_1 x_2=x_3 x_4)$.  Then the function $\frac{x_1}{x_3}=\frac{x_4}{x_2}$ is well defined all over $Spec(R)$ but the expression $\frac{x_1}{x_3}$ only works for it when $x_3\neq 0$ and correspondingly for $\frac{x_4}{x_2}$.  The points that get excluded by inverting $x_3$ are not excluded by inverting $x_2$.
