Skip to content
Prev 58880 / 398503 Next

scan or source a text file into a list

On Thu, 11 Nov 2004, Andy Bunn wrote:

            
I think I would be tempted to try out read.dcf() for this, which returns a 
character matrix of field values in named columns, from which values cast 
to numeric:
nYears: 50
year0: 1970
fnr: 0.30
qe: 0.040
nYears year0  fnr    qe     
[1,] "50"   "1970" "0.30" "0.040"
chr [1, 1:4] "50" "1970" "0.30" "0.040"
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "nYears" "year0" "fnr" "qe"


Since you will know the mode you need, you could read the same-mode fields 
together and cast them:
nYears year0
[1,]     50  1970

and make x a data frame if say x$nYears is needed, which gets to list:
$nYears
[1] 50

$year0
[1] 1970

and c() of the different mode lists to make inputParamList. I think 
treating everything as numeric may be enough, and the DCF format is 
flexible.

Roger