If function is Riemann integrable on a closed interval, does it have a primitive function on the interval? I'm trying to solve the following theoretical question:

If function is Riemann integrable on interval [a,b], does it have a
  primitive function on [a,b]?

My solution is the following: 
$f(x)=\left\{\begin{matrix}
1, & x\in \left [ 0,2 \right )\\ 
2, & x\in \left [ 2,4 \right ]
\end{matrix}\right.$
The following function is Riemann integrable on [0,4] but a primitive function does not exist on interval [0,4]. Therefore the statement is not correct. Is it correct? If not, could you help me fix it?
 A: This is false. There are many functions that are not the derivative of anything, yet they may have integrals.
In particular, no function with a simple discontinuity is a derivative. Thus, any such function that is bounded will serve as counterexample.
A: The wiki article https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus is quite informative on the subject.
If you consider purely Riemann integration you are stuck with the need for continuity of $f$.
But if you allow for generalisations (Lebesgue, KH), then you get the notion of equality almost everywhere of $F'$ and $f$.
In paragraph Generalizations of the above article you can read: 
However, if F is absolutely continuous, it admits a derivative F′(x) at almost every
point x, and moreover F′ is integrable, with F(b) − F(a) equal to the integral of F′ 
on [a, b]. Conversely, if f is any integrable function, then F as given in the first 
formula will be absolutely continuous with F′ = f a.e.

Yet, here with a finite number of points of discontinuity, you can nevertheless apply the paragraph called Second part or Newton Leibniz's axiom. 
That is if you define $F(x)=x,\ 2x-2$ on the respective intervals you get that $F'=f$ in any closed interval $K\subset[0,2)\text{ or }(2,4]$ (namely in any $[0,2-\epsilon]$ or $[2+\epsilon,4]$).
