I have a CSV file:
% head -5 arf.csv
ENERG_LO,ENERG_HI,SPECRESP
0.3000000, 0.3100000, 4.874343
0.3100000, 0.3200000, 14.82926
0.3200000, 0.3300000, 21.30229
0.3300000, 0.3400000, 28.51495
which I can read with Frames
, and do basic manipulation, but I can't seem
to select a column. Could this be a user issue (missing something or using the
wrong symbol) or perhaps an IHaskell one?
-- Not all of these are needed, but better be safe than sorry
:set -XConstraintKinds
:set -XDataKinds
:set -XFlexibleContexts
:set -XGADTs
:set -XOverloadedStrings
:set -XPatternSynonyms
:set -XQuasiQuotes
:set -XScopedTypeVariables
:set -XTemplateHaskell
:set -XTypeOperators
:set -XViewPatterns
-- Not sure I'm going to use all these
import qualified Control.Foldl as L
import qualified Data.Foldable as F
import Control.Applicative
import Data.Proxy (Proxy(..))
import Lens.Family
import Frames
import Frames.CSV (readTableOpt)
tableTypes "ARF" "arf.csv"
As a side note: some of the auto-generated symbols here are
visually jarring (to me, such as aRFParser
) since the default name changes don't
really match well with the all-upper-case approach the
file has for column names.
arfStream = readTableOpt aRFParser "../data/arf.csv"
arf <- inCoreAoS arfStream :: IO (Frame ARF)
As a check things are working:
columnHeaders (Proxy :: Proxy ARF)
["ENERG_LO","ENERG_HI","SPECRESP"]
mapM_ print (take 3 (F.toList (view sPECRESP <$> arf)))
4.874343 14.82926 21.30229
L.fold L.maximum (view sPECRESP <$> arf)
Just 672.1996
showFields (frameRow arf 0)
["0.3","0.31","4.874343"]
Now I'd like to select just the SPECRESP
column. From the
tutorial,
I tried the following, but got a kind error:
select (Proxy::Proxy [SPECRESP]) $ frameRow arf 0
Unsurprisingly I also get it when using a function (rather than type annotation):
sprespOnly :: ARF -> Record [SPECRESP]
sprespOnly = rcast
Am I wrong to think that I should be using the SPECRESP
type/symbol here?
The only other "obvious-to-me" symbol would be Specresp
, but this isn't defined:
foo :: ARF -> Record [Specresp]
foo = rcast