Consider the function $f: (0,1) \rightarrow \mathbb{R}$.
$f(n) =\left\{
\begin{array}{ll}
\dfrac{1}{x} - 2 & \text{if}\ 0 < x \leq \dfrac{1}{2}\\
\dfrac{1}{x-1} + 2 & \text{if} \ \dfrac{1}{2} < x < 1
\end{array}
\right.$
We claim that $f$ is a bijective function between the open unit interval $(0,1)$ and $\mathbb{R}$ that takes rationals to rationals and irrationals to irrationals.
First, we notice that $f$ is piece-wise defined in such a way that $dom \ f$ partitions the open unit interval into two sets $S$ and $R$ defined by $S = \left \{ x \in \mathbb{R} \ | \ x \in (0,\dfrac{1}{2}] \right\}$ and $R = \left \{ x \in \mathbb{R} \ | \ x \in (\dfrac{1}{2},1) \right\}$.
Second, we show that $f$ takes rationals only to rationals and irrationals only to irrationals. There are a total of four cases to consider.
$\bf{Case \ \#1}$: Say $x \in S \cap \mathbb{Q}$. Then, by the definition of our function $f$, $\exists a,b \in \mathbb{Z}$ such that $x = \dfrac{a}{b}$ and $f(x) = \dfrac{b}{a} - 2$ and $b \neq 0$ because every rational $x$ can be represented as a ratio of two integers, with the denominator non-zero. Since rationals are closed under division and subtraction, we know that $\dfrac{b}{a} - 2$ is rational.
$\bf{Case \ \#2}$: Say $x \in R \cap \mathbb{Q}$. Then, by the definition of our function $f$, $\exists a,b \in \mathbb{Z}$ such that $x = \dfrac{a}{b}$ and $f(x) = \dfrac{1}{\dfrac{a}{b}-1} + 2$. Since rationals are closed under division, subtraction, and addition, we know that $\dfrac{1}{x-1} + 2$ is rational.
This shows that $\forall x \in (0,1) \cap \mathbb{Q}, f(x) \in \mathbb{Q} \subseteq \mathbb{R}$. So every rational in the open interval is mapped to a rational.
$\bf{Case \ \#3}$: Say $x \in S \cap (\mathbb{R} - \mathbb{Q}$). Then, by the definition of $f$, $\sim \exists a,b \in \mathbb{Z}$ such that $f(x) = \dfrac{b}{a} - 2$. Since both the subtraction and division of an irrational number by a rational number still produces an irrational number, we know that $\dfrac{b}{a} - 2$ is irrational.
$\bf{Case \ \#4}$: Say $x \in R \cap (\mathbb{R} - \mathbb{Q}$). Then, by the definition of $f$, $\sim \exists a,b \in \mathbb{Z}$ such that $f(x) = \dfrac{1}{\dfrac{a}{b}-1} + 2$. Since the subtraction, division, and addition of an irrational number with a rational number produces an irrational number, we know that $\dfrac{1}{\dfrac{a}{b}-1} + 2$ is irrational.
Therefore, $f$ maps irrationals only to irrationals.
Thirdly, we must show that $f$ is a bijective function.
To prove injectivity, there are two cases:
$\bf{Case \ \#1}$: Let $f(x) = f(y)$, where $x,y \in S \cap \mathbb{Q}$. Then, $\exists a,b,c,d \in \mathbb{Z}$, where $b,d \neq 0$, and $x = \dfrac{a}{b}$ and $y = \dfrac{c}{d}$ such that $\dfrac{b}{a} - 2 = \dfrac{d}{c} -2$. Adding both sides by two, we get $\dfrac{b}{a} = \dfrac{d}{c}$ which implies that $\dfrac{a}{b} = \dfrac{c}{d}$. So $x = y$ and $f$ is injective.
$\bf{Case \ \#2}$: Let $f(x) = f(y)$, where $x,y \in R \cap \mathbb{Q}$. Then, $\exists a,b,c,d \in \mathbb{Z}$, where $b,d \neq 0$, and $x = \dfrac{a}{b}$ and $y = \dfrac{c}{d}$ such that $\dfrac{1}{\dfrac{a}{b}-1} + 2 = \dfrac{1}{\dfrac{c}{d}-1} + 2$. Subtracting both sides by 2 we get $\dfrac{1}{\dfrac{a}{b}-1} = \dfrac{1}{\dfrac{c}{d}-1}$. This implies that $\dfrac{c}{d} - 1 = \dfrac{a}{b} -1$. Adding both sides by 1, we get $y = x$ so $f$ is injective.
To prove surjectivity, there are four cases:
$\bf{Case \ \#1}$: We show that $\forall y \in \mathbb{Q}$, $y = f(x)$ for some $x \in S \cap \mathbb{Q}$. Let $f(x) = y$; so $y = \dfrac{1}{x} - 2$. Then, $x = \dfrac{1}{y+ 2}$ and we are done.
$\bf{Case \ \#2}$: We show that $\forall y \in \mathbb{Q}$, $y = f(x)$ for some $x \in R \cap \mathbb{Q}$. Let $f(x) = y$; so $y = \dfrac{1}{x-1} + 2$. Then, $x = \dfrac{1}{y-2} + 1$ and we are done.
$\bf{Case \ \#3}$: We show that $\forall y \in (\mathbb{R} - \mathbb{Q})$, $y = f(x)$ for some $x \in S \cap (\mathbb{R} - \mathbb{Q})$. Let $f(x) = y$; so $y = \dfrac{1}{x} - 2$. Then, $x = \dfrac{1}{y+ 2}$ and we are done.
$\bf{Case \ \#4}$: We show that $\forall y \in (\mathbb{R} - \mathbb{Q})$, $y = f(x)$ for some $x \in R \cap (\mathbb{R} - \mathbb{Q})$. Let $f(x) = y$; so $y = \dfrac{1}{x-1} + 2$. Then, $x = \dfrac{1}{y-2} + 1$ and we are done.
This completes our proof that $f$ is a bijective function between the open unit interval $(0,1)$ and $\mathbb{R}$ that takes rationals to rationals and irrationals to irrationals.