Is it possible to extend an arbitrary smooth function on a closed subset of $R^n$ to a smooth function on $R^n$? Assume that $K$ is a closed (or compact if necessary) subset in $\mathbb{R^n}$ and $f:K \rightarrow \mathbb{R}$ is a smoth function in the following sense:
for each $x \in K$ there exists a neighbourhood $V_x$  in $\mathbb{R}^n$ of $x$ and a function $F_x: V_x \rightarrow \mathbb{R}$ of class $C^\infty(V_x)$ such that $F_x| (V_x \cap K)=f|(V_x \cap K)$.
Is it posible to extend $f$ to a function of class $C^\infty$ on $\mathbb{R}^n$ ?
 A: Yes, you may extend $f$ to a $C^\infty$ function on $\mathbb R^n$.   
The local conditions you give on the function $f:K\to \mathbb R$ say exactly that $f$ is a section on $K$ of the sheaf $ C^\infty_{\mathbb R^n}$,  i.e. $f\in \Gamma (K, C^\infty_{\mathbb R^n})$.
This sheaf is fine, a translation of the existence of partitions of unity on $\mathbb R^n$,  hence soft (see here and here  ) and thus by definition of soft, this implies  that the restriction map $$\Gamma (\mathbb R^n, C^\infty_{\mathbb R^n})=C^\infty (\mathbb R^n) \to  \Gamma (K, C^\infty_{\mathbb R^n}):F\mapsto F\mid K$$ is surjective, answering your question in the affirmative.  
Remarks
1) The closed set $K$ does not have to be compact.
In fact the result and its proof generalize word for word to the case of a closed subset of a paracompact differential  manifold.
2) One could unpack everything I wrote so as to eschew the use of sheaves, but I would rather consider that the ease with which you can solve such a question is good propaganda for sheaves, which are a very easy notion anyway ( at least as long as cohomology is not introduced).
A: Say we have a closed subset $F$ of a manifold $X$ (paracompact), $f\colon F \to \mathbb{R}$, such that there exists $U_i$ family of open subsets covering $F$ and $f_i$ smooth functions on $U_i$ such that $f_i\ _{|U_i\cap F}= f_{|U_i\cap F}$ ( $f$ is locally restriction of a smooth function on $X$). 
Consider the cover $U_i, U_0=X\backslash F$ of $X$. There exists a partition of unity associated to this cover, that is $\phi_i$, $\phi_0$ with $\operatorname{supp} \phi_l \subset U_l$, $\operatorname{supp} \phi_l$ locally finite, and $\sum \phi_l=1$.  The function $\phi_i f_i$ can be extended to a smooth function on $X$, defined by $\phi_i f_i$ on $U_i$ and by $0$ on $X \backslash \operatorname{supp}\phi_i$. Let $F = \sum_i \phi_i f_i$. Consider $x \in F$. Let $i_1$,$\ldots$, $i_k$ the finitely many indexes for which $\phi_l(x) \ne 0$. They are not $0$. Therefore, $x \in U_{i_s}$, $s=1,\ldots, k$, and  $f_{i_s}(x) = f(x)$.  We have $F(x) = \sum_{s} \phi_{i_s} f(x) =f(x)$. 
Note: Why did we need $F$ closed?  Otherwise we would have gotten a smooth extension only on an open neighborhood of the set.  
