I remember hearing that (all) topological spaces are retracts of CW-complexes. Given a topological space $X$, I am trying to construct a CW-complex $Y$ with continuous morphisms $i:X\to Y$ and $r:Y\to X$, such that $r \circ i=\mathrm{id}_X$, but with no luck so far.
Could you please provide a reference, in case the statement is correct, or a counterexample otherwise.
For another simple way to get counterexamples, note that every CW-complex is Hausdorff. Every subspace of a Hausdorff space is Hausdorff, so if $X$ is any non-Hausdorff space then it cannot embed in a CW-complex (and in particular, it cannot be a retract of a CW-complex).
You can similarly get counterexamples using other nice properties of CW-complexes that are inherited by subspaces (or even just which are inherited by closed subspaces, since a retract of a Hausdorff space is a closed subset). For instance, every CW-complex is perfectly normal (a fairly strong separation axiom), and thus so is any retract of a CW-complex.