f# - Infer the type information for any arbitrary CSV files? -
i want use following console program type information (not data) of csv type provider. file name passed command line argument. however, seems csvprovider<>
accept constant literal.
is there way workaround it? or possible using f# script? or can f# compiler service help?
or there other project this?
open fsharp.data open microsoft.fsharp.collections open system [<literal>] let fn = """c:\...\myfile.csv""" // want dynamically set fn arguments [<entrypoint>] let main argv = let myfile = csvprovider<fn>.getsample() // following doesn't work let fn = argv.[0] let myfile = csvprovider<fn>.getsample() // code type information of myfile
i think might misunderstanding purpose of csv type provider - idea have representative sample of data available @ compile time (and can use guide type inference). @ runtime, give (possibly different) file same format. gives nice way of handling files known format.
if want parse arbitrary csv files (with different headers etc.) csv type provider won't help. however, can still use csvfile
type f# data provides simple csv parser. example from documentation:
// download stock prices let msft = csvfile.load("http://ichart.finance.yahoo.com/table.csv?s=msft") // print prices in hloc format row in msft.rows printfn "hloc: (%s, %s, %s)" (row.getcolumn "high") (row.getcolumn "low") (row.getcolumn "date")
here, loose nice static typing, can load file format (and dynamically @ columns available in file).
Comments
Post a Comment