Q:

How to use \ref to print the value of a counter the way it was originally produced? 

I want to number the lines in a table with roman numerals, and then when I cross-reference them have the reference printed in the same way. 
For example,
\documentclass{article}
\begin{document}
\newcounter{foo}
\newcommand{\rfoo}{\refstepcounter{foo}(\roman{foo})}

\begin{tabular}{r|l}

\hline

\rfoo\label{f1} & First line \\ \hline

\rfoo\label{f2} & Second line \\ \hline

\hline
\end{tabular}

\

The first line is \ref{f1}.   The second line is \ref{f2}. 

\end{document}

gives

But what I want is:

A:

Each counter has a fellow macro called \the..., say counter foo will have \thefoo.  This \the... macro does by default the output of the counter value with arabic numbers. 
\thefoo is used also for the label as it is written to the .aux file.  If format (i), is requested, this has to be written into the .aux file and it's to be used in \thefoo. 
So
\renewcommand{\thefoo}{(\roman{foo})}

is the name of the game ;-)
\documentclass{article}

\newcounter{foo}
\renewcommand{\thefoo}{(\roman{foo})}
\newcommand{\rfoo}{\refstepcounter{foo}\thefoo}

\begin{document} 
\begin{tabular}{r|l}

\hline

\rfoo\label{f1} & First line \\ \hline

\rfoo\label{f2} & Second line \\ \hline

\hline
\end{tabular}

The first line is \ref{f1}.   The second line is \ref{f2}. 

\end{document}

Here the automatic row numbering version
\documentclass{article}

\usepackage{array}

\newcounter{foo}
\renewcommand{\thefoo}{(\roman{foo})}

% Define
\newcolumntype{R}{>{\refstepcounter{foo}\thefoo\arraybackslash}r}

\begin{document}

\begin{tabular}{R|l}

\hline

\label{f1} & First line \\ \hline

\label{f2} & Second line \\ \hline

 & ... line \\ \hline

\label{f4}  & ... line \\ \hline

\hline
\end{tabular}

\

The first line is \ref{f1}.   The second line is \ref{f2}. 

And in line \ref{f4} you can see that

\end{document}

