Is a function null if its integrals over all rectangles vanish? In answering this question we have used the following result.
Lemma If a measurable function $f \colon \mathbb{R}^n \to \mathbb{R}$ is such that, for every (compact) rectangle $R$,
$$\int_R f(x)\,dx=0,$$
then $f=0$ almost everywhere.
I'm pretty much sure this is true, both for recalling having read about it somewhere and for its intuitive obviousness. However, when cooking up a proof, I couldn't avoid making use of the additional assumption $f \in L^1_{\rm{loc}}(\mathbb{R}^n)$. You can read my try here (I've explicitly mentioned the point in which the additional assumption is exploited).
How to dispense with that?
EDIT: Answer to comments
In comments below Didier, Julian and Byron noted that the condition $\int_R f(x)\,dx=0$ on the rectangle $R$ implicitly says $f \in L^1(R)$. And so, requiring it to hold for every compact rectangle implies $f \in L^1_{\rm{loc}}(\mathbb{R}^n)$. Of course you're right: to sum things up, my question is totally trivial!!! :-)
I guess it is now universally clear that I'm a novice (still a student, in fact).
Thank you very much for helping.
 A: As I understand this post, the OP asks about the necessity, or not, of the hypothesis that $f\in L^1_{\mathrm{loc}}(\mathbb{R}^n)$ for the lemma to hold (as opposed to, how to prove the lemma). 
But the hypothesis of the lemma makes no sense unless  $f\in L^1_{\mathrm{loc}}(\mathbb{R}^n)$ since, to be simply able to write something like $\displaystyle\int_Rf(x)\mathrm{d}x$, one must assume that $f\in L^1(R)$. And to ask that $f\in L^1(R)$ for every (compact) rectangle $R$ is equivalent to asking that $f\in L^1_{\mathrm{loc}}(\mathbb{R}^n)$.
A: As noted by user8268 (and by Didier as I was writing this), your assumption implies that $f$ is locally integrable. The definition of integral for a signed function $f$ includes the condition that the integral of $f^+$ or of $f^-$ is finite.
Now, the Lebesgue differentiation theorem implies that if the integral of $f$ vanishes on all rectangles, then  $f=0$ almost everywhere. It is even enough that the integral vanishes on a family of rectangles of eccentricity between two bounds $M$ and $M^{-1}$.
A: Let's write $f(x)=g(x)-h(x)$ where $g$ and $h$ are the positive and negative part of $f$. Then $\int_rg=\int_rh<\infty$ for every rectangle $r$ by your assumption.  Let us restrict from $\mathbb{R}^n$ to a rectangle $P$. It's enough to show that $f$ is 0 a.e. in $P$ for every $P$. Now $\mu_1:A\mapsto\int_A g$ and  $\mu_2:A\mapsto\int_A h$ ($A\subset P$ measurable) are finite measures on $P$. We have $\mu_1(r)=\mu_2(r)$ for every rectangle $r\subset P$ by your assumption. Since rectangles form a $\pi$-system, we know that $\mu_1=\mu_2$ by Dynkin theorem (=monotone class theorem). Hence $g=h$ a.e., hence $f=g-h=0$ a.e.
Edit: thanks to Nate (replaced $\lambda$ by $\pi$)
