What is an example of $\mathscr O_{Spec R}(U)\neq S^{-1}R$ for some $S$ consisting of the elements of $R$ not vanishing on $U$? I've been meditating on the very basics of algebraic geometry, and in particular on how exactly $X=\operatorname{Spec} R$ relates to its structure sheaf $\mathscr O_X$.
In these meditations, I've realized that the only $\mathscr O_X(U)$ for open subsets $X\setminus V(I)=U\subset X$ that I've come across have turned out to be $S^{-1}R$ where $S=\{f\in R \ \colon \ V(f)\subset V(I)\}$, i.e. they have always been the localization of $R$ at the set of elements of $R$ which do not vanish on $U$. It is easy to see that $S^{-1}R$ is the direct limit of $\mathscr O_X(X_s)=R_s$ (localizations of $R$ at ${1,s,s^2,\dots}$) for those $s$ that don't vanish on $U$.
However, the actual definition of the sheaf requires that $\mathscr O_X(U)$ be the inverse limit of $\mathscr O_X(X_f)=R_f$ for those $f$ that vanish on the every point of the complement of $U$ (i.e. for $f$ such that $X_f\subset U$).
Evidently, the former admits a unique morphism into the latter, as the former is an initial object and the latter a terminal object. I strongly suspect that the two constructions are different in general (otherwise why torture us beginners with the counter-intuitive inverse limit definition), but I have been unable to come up with an example where the two diverge. 
 A: Consider the Segre cone $S=Spec (A) $ with $A=\mathbb C[X,Y,Z,W]/(XW-YZ)=\mathbb C[x,y,z,w]$.
In  other words $S$ is the  hypersurface given by the  equation $xw-yz=0$ in $\mathbb A ^4 _{\mathbb C}$.
That hypersurface $S$   contains the closed plane $P\subset \mathbb A ^4 _{\mathbb C}$ given by the equations $y=w=0$.
  Call $U$ the open complement $U=S\setminus P$.
Then I claim that $\mathcal O_S(U)$ cannot be obtained as a ring of fractions $T^{-1}A$ of the domain $A$.
Indeed, the function $x/y$ on the open subset $D(y) \subset S$ defined by $y\neq 0$ and the function $z/w$ on the open subset $D(w) \subset S$ defined by $w\neq 0$ glue together to yield a function $f\in \mathcal O_S(U)$.
That function $f$  cannot be written $g/h$, no matter how $g,h \in \mathcal O_S(U)$ ($h$ without  zero on $U$) are chosen.
(It is a reasonable   exercise  on complex polynomials in $X,Y,Z,W$ to show this impossibility) 
Edit
As user 18119 very judiciously remarks, if $I\subset A$ is the set of $\phi\in A$ invertible on $U$, then from $\mathcal O_S(U)= T^{-1}A$ we deduce $T\subset I$ and then  $\mathcal O_S(U)=T^{-1}A\subset I^{-1}A \subset I^{-1}\mathcal O_S(U)=O_S(U)$ so that $\mathcal O_S(U)=I^{-1}A$.
In other words:  if $\mathcal O_S(U)=T^{-1}A$, then also $\mathcal O_S(U)=I^{-1}A$.
[Beware that I don't claim that the original $T$ was equal to $I$ !]
A: Let me give two examples. 


*

*Let $X=\mathrm{Spec}(R)$ be an integral affine surface with an isolated non-normal point $p$. Let $U=X\setminus \{ p\}$. If $f\in S$, then $V(f)\subseteq \{ p \}$ and $V(f)=\emptyset$ because otherwiser it has dimension $1$. Therefore $S=R^*$ and $S^{-1}R=R$. But $O_X(U)$ is not equal to $R$ because $R$ is not integrally closed while $O_X(U)$ is. In this example, $X$ is not normal and $U$ is not affine. 

*Here is an example with $X$ regular and $U$ affine. Let $C$ be a smooth projective curve of genus $g>0$ over an uncountable field $k$ (e.g. $k=\mathbb C$). Let $p, q\in C(k)$ be two rational points such that $p-q$ is not a torsion point in the Jacobian $J$ of $C$. Such $p, q$ exist by the hypothesis on $k$ (otherwise $J(k)$ would be of torsion, hence countable). Let $X=C\setminus \{q\}$ and $U=X\setminus \{ p \}$. Then $X$ and $U$ are regular and affine, and $O(X)\to O(U)$ is not an isomorphism because $U\ne X$. Let's show that in this case again $S=O(X)^*=k^*$. Let $f\in S$. Its divisor $\mathrm{div}(f)$ has support in $\{p, q\}$ and degree $0$:
$$ \mathrm{div}(f)=n(p-q).$$ 
In other words, $n(p-q) \sim 0$. As $p-q$ is not torsion, $n=0$ and $f\in k^*$.
In a more positive direction, if $R$ is a UFD, then it is easy to see that $O(U)=S^{-1}R$ whatever $U$ is affine or not. 
Update To write down an explicit example of surface $X$ as in 1, identify two distinct rational points in the affine plane. Algebraically, 
$$ R=\{ f\in k[x,y] | f(0,0)=f(0,1) \}.$$
Or consider $R=\{ f\in k[x,y] | \partial f/\partial x(0,0)=\partial f/\partial y(0,0)= 0 \}=k+(x,y)^2k[x,y]$ (pinch the origin in the affine plane). 
A: Let $R$ be a boolean ring (every element is idempotent). It is easy to see that every localization map $R \to S^{-1} R$ is surjective. But not every restriction map $R = \mathcal{O}(\mathrm{Spec}(R)) \to \mathcal{O}(U)$ is surjective: 
Let $R$ be the unitalization of the $\mathbb{F}_2$-algebra $\mathbb{F}_2^{(\mathbb{N})}$. It maybe regarded as the subring of $\mathbb{F}_2^\mathbb{N}$ generated by the standard basis vectors $e_1,e_2,...$. The restriction map to $U = \cup_i D(e_i)$ corresponds to the inclusion $R \hookrightarrow \mathbb{F}_2^\mathbb{N}$. It is not surjective (for example, $(1,0,1,0,1,...)$ is not in the image).
By the way, $\mathrm{Spec}(R)$ is the one-point-compactification of $U=\mathbb{N}$, endowed with the constant sheaf $\underline{\mathbb{F}_2}$.
