Extending a continuous function defined on a subset of $\mathbb{R}$ Let $E$ be a subset of $\mathbb{R}$ and let $f$  be a continuous function defined on $E$. Is it true that $f$ can always be extended to a function $\tilde{f}$ defined on $\mathbb{R}$, which is still continuous on $E$? I know that
we cannot ask $\tilde{f}$ be to continuous on all $\mathbb{R}$,
which is shown by the following example:
Does every continuous map from $\mathbb{Q}$ to $\mathbb{Q}$ extends continuously as a map from $\mathbb{R}$ to $\mathbb{R}$?
Thank you in advance!
Edit: I wanted ask if $\tilde{f}$ could be continuous at every point of $E$. I hope it's clearer phrased this way!
Edit2: From comments. For example, if $E=\{0\}$, then $f$ with $f(0)=0$ is continuous. If we define $\tilde{f}(x)=1$ for $x\in\mathbb{R}\backslash\{0\}$ (and $\tilde{f}(x)=f(x)$ for $x\in E$), then the
restriction of $\tilde{f}$ to $E$ is continouous but $\tilde{f}$ is not continuous at $0$.
 A: Given $f:E \to  \mathbb R $ continuous on $E$, define $\tilde f:\mathbb R \to \mathbb R  $ as follows:

*

*For $\, x \in E\, $, let $\, \tilde f(x):=f(x)$.


*If $x \in \overline{E}\setminus E$ and $\displaystyle \limsup_{E \ni t \to x} f(t)\in {\pm \infty}\, , \,$  let $\tilde f(x):=0$.


*If $x \in \overline{E}\setminus E$ and $\displaystyle  \limsup_{E \ni t \to x} f(t)\in \mathbb R  \, , \,$  let $\displaystyle  \tilde f(x):=  \limsup_{E \ni t \to x} f(t)$.


*If $x \in \mathbb R \setminus \overline{E}\, , \, $ let $\, d(x,E):=\inf_{t \in E} |x-t|$, and define
$$ \tilde f(x):= \inf \{f(t) \, : \, t\in E, \, \, \,\; |t-x| \le 2d(x,E)\}\,.$$
It remains to check continuity of $\tilde f$ in points of $E$.
Given $z \in E$ and $\epsilon>0$, we know there exists $\delta>0$ such that
$$\forall t \in E \cap(z-\delta,z+\delta), \quad |f(t)-f(z)| <\epsilon/2 \,.$$
Now suppose that $x \in  \mathbb R \setminus {E}$ satisfies $|x-z|<\delta/3$.
Then there are two possibilities:
(a) If $x\in \overline{E}$, then we must have $\displaystyle \limsup_{E \ni t \to x} f(t) \in [f(z)-\epsilon/2, f(z)+\epsilon/2]$, so in particular
$$|\tilde f(x)-f(z)|<\epsilon \,. $$
(b) If $x\notin \overline{E}$, then $0<d(x,E) < \delta/3$, so all $t\in E$ such that $|t-x| \le 2d(x,E)< 2\delta/3$ satisfy $|t-z| <\delta$. Therefore
$$|\tilde f(x)-f(z)|\le \epsilon/2 <\epsilon \,. $$
