如何最好地将.cfl文件读入R

时间:2019-07-10 17:57:32

标签: r

我正在尝试读取.CFL文件,该文件是控制文件或映射文件,然后将用于处理现有数据(来自FAO的PSD数据)。我正在尝试找出如何读取.cfl文件,以使其跳过注释,然后将表格的其余部分组织成一种不错的格式。一种方法是将所有内容复制粘贴到Excel中,并将其组织成格式良好的列,然后阅读。但是我想知道是否有一种方法可以绕开它,并将.CFL直接读入R。在下面的.CFL文件中,我想读取商品代码和名称,但是跳过所有注释块(!,/ * ,* /)

!         PS&D commodity definitions and aggregations.

!   Comments are indicated by the following symbols, starting in column 1:
!   !   begins a comment line.
!   /*  begins a comment block.
!   */  ends   a comment block.


! Table:  Define commodities
! |          CSV commodity code; input or aggregate.  Output order implied.  This field is treated as text.
! |          (Many of the numeric codes match SITC Revision 3, http://www.intracen.org/tradstat/sitc3list.htm)
! |          |        TS file name; output
! |          |        |         TS commodity name; output
! |          |        |         |                        First output year.  Default=all years.
! |          |        |         |                        |     Year offset, from CSV file year (left-hand number) to TS year.  Default=0.
! |          |        |         |                        |     |   Print empty tables:  1=yes, 0=no=default
! |          |        |         |                        |     |   |  Comments
! ---------  -------  --------  -----------------------  ----  --  -  ......
  COMMODITY  0011000  CATTLE    Cattle
  COMMODITY  0013000  SWINE     Swine

  COMMODITY  0111000  BFVEAL    Beefveal
  COMMODITY  0113000  PORK      Pork
  COMMODITY  0114000  POULTRY_  Poultry_Chicken+Turkey
  COMMODITY  0115000  CHICKEN   Chicken
  COMMODITY  0114300  TURKEY    Turkey
  COMMODITY  EGGS     EGGS      Eggs
  COMMODITY  LAMBMUT  LAMBMUT   Lamb Mutton

  COMMODITY  0223000  FLUIDMK   Fluid Milk
  COMMODITY  0224200  NFDMILK   Nonfat Dry Milk
  COMMODITY  0224400  DAIRYDM   Dairy Dry Milk
  COMMODITY  0230000  BUTTER    Butter
  COMMODITY  0240000  CHEESE    Cheese

  COMMODITY  0410000  WHEAT     Wheat
  COMMODITY  0422110  RICE      Rice
  COMMODITY  0430000  BARLEY    Barley
  COMMODITY  0440000  CORN      Corn
  COMMODITY  0451000  RYE       Rye
  COMMODITY  0452000  OATS      Oats
  COMMODITY  0459100  MILLET    Millet
  COMMODITY  0459200  SORGHUM   Sorghum
  COMMODITY  0459900  MIXGRNS   Mixed Grains
  COMMODITY  CGRAINS  CGRAINS   Coarse Grains
  COMMODITY  TOTGRNS  TOTGRNS   Total Grains

  COMMODITY  0612000  SUGAR     Sugar

  COMMODITY  0813100  SOYMEAL   Soybean Meal
  COMMODITY  0813200  PNUTML    Peanut Meal
  COMMODITY  0813300  COTMEAL   Cottonseed Meal
  COMMODITY  0813500  SUNMEAL   Sunflower Meal
  COMMODITY  0813600  RAPEML    Rape Meal
  COMMODITY  0813700  COPMEAL   Copra Meal
  COMMODITY  0813800  PKERNML   Palm Kernel Meal
  COMMODITY  0814200  FISHML    Fish Meal
  COMMODITY  TOTMEAL  TOTMEAL   Total Meals

  COMMODITY  2221000  PEANUTS   Peanuts
  COMMODITY  2222000  SOYBEAN   Soybean
  COMMODITY  2223000  COTSEED   Cottonseed
  COMMODITY  2224000  SUNSEED   Sunflowerseed
  COMMODITY  2226000  RAPESD    Rapeseed
  COMMODITY  2231000  COPRA     Copra
  COMMODITY  2232000  PALMKRN   Palm Kernel
  COMMODITY  TOTSEED  TOTSEED   Total Seeds              1961

  COMMODITY  2631000  COTTON    Cotton
  COMMODITY  COTBALE  COTTONBA  Cotton (bales)                     0

  COMMODITY  4232000  SOYOIL    Soybean Oil
  COMMODITY  4233000  COTOIL    Cottonseed Oil
  COMMODITY  4234000  PNUTOIL   Peanut Oil
  COMMODITY  4235000  OLIVOIL   Olive Oil
  COMMODITY  4236000  SUNOIL    Sunflower Oil
  COMMODITY  4239100  RAPEOIL   Rape Oil
  COMMODITY  4242000  CNUTOIL   Coconut Oil
  COMMODITY  4243000  PALMOIL   Palm Oil
  COMMODITY  4244000  PKEROIL   Palm Kernel Oil
  COMMODITY  VEGOILS  VEGOILS   Vegetable Oils
  COMMODITY  TROPOIL  TROPOIL   Tropical Oils
  COMMODITY  TOTOILS  TOTOILS   Total Oils
! ---------  -------  --------  -----------------------  ----  --  -  ......



! Table:  Define generic commodity aggregations.  Fine-tuning possible in VarCsvTs.cfl.
! |          Output (aggregate) commodity
! |          |        Operator:  + -
! |          |        | Input Csv commodity to be included in aggregate
! |          |        | |        Comments
! -------    -------  - -------  ......

!Poultry, Meat, Total.  Change aggregate code if FAS provides total Poultry Meat
!                       again (unlikely); same code used.
  COMAGGR    0114000  + 0115000  'Plty, Meat, Chicken -16 wks'
  COMAGGR    0114000  + 0114300  'Poultry, Meat, Turkey'

! Total coarse grains
  COMAGGR    CGRAINS  + 0430000  'Barley
  COMAGGR    CGRAINS  + 0440000  'Corn
  COMAGGR    CGRAINS  + 0451000  'Rye
  COMAGGR    CGRAINS  + 0452000  'Oats
  COMAGGR    CGRAINS  + 0459100  'Millet
  COMAGGR    CGRAINS  + 0459200  'Sorghum
  COMAGGR    CGRAINS  + 0459900  'Mixed Grains

! Total oilseeds
  COMAGGR    TOTSEED  + 2221000  'Oilseed, Peanut
  COMAGGR    TOTSEED  + 2222000  'Oilseed, Soybean
  COMAGGR    TOTSEED  + 2223000  'Oilseed, Cottonseed
  COMAGGR    TOTSEED  + 2224000  'Oilseed, Sunflowerseed
  COMAGGR    TOTSEED  + 2226000  'Oilseed, Rapeseed
  COMAGGR    TOTSEED  + 2231000  'Oilseed, Copra
  COMAGGR    TOTSEED  + 2232000  'Oilseed, Palm Kernel

! Total oils
! COMAGGR    TOTOILS  + 4111100  'Oil, Fish
! COMAGGR    TOTOILS  + 4113200  'By-Products,Tallow & Grease
  COMAGGR    TOTOILS  + 4232000  'Oil, Soybean
  COMAGGR    TOTOILS  + 4233000  'Oil, Cottonseed
  COMAGGR    TOTOILS  + 4234000  'Oil, Peanut
  COMAGGR    TOTOILS  + 4235000  'Oil, Olive
  COMAGGR    TOTOILS  + 4236000  'Oil, Sunflowerseed
  COMAGGR    TOTOILS  + 4239100  'Oil, Rapeseed
  COMAGGR    TOTOILS  + 4242000  'Oil, Coconut
  COMAGGR    TOTOILS  + 4243000  'Oil, Palm
  COMAGGR    TOTOILS  + 4244000  'Oil, Palm Kernel

! Veg oils
  COMAGGR    VEGOILS  + 4232000  'Oil, Soybean
  COMAGGR    VEGOILS  + 4233000  'Oil, Cottonseed
  COMAGGR    VEGOILS  + 4234000  'Oil, Peanut
  COMAGGR    VEGOILS  + 4235000  'Oil, Olive
  COMAGGR    VEGOILS  + 4236000  'Oil, Sunflowerseed
  COMAGGR    VEGOILS  + 4239100  'Oil, Rapeseed
  COMAGGR    VEGOILS  + 4242000  'Oil, Coconut
  COMAGGR    VEGOILS  + 4243000  'Oil, Palm
  COMAGGR    VEGOILS  + 4244000  'Oil, Palm Kernel

! Tropical Oils
  COMAGGR    TROPOIL  + 4242000  'Oil, Coconut
  COMAGGR    TROPOIL  + 4243000  'Oil, Palm
  COMAGGR    TROPOIL  + 4244000  'Oil, Palm Kernel

! Total meals
  COMAGGR    TOTMEAL  + 0813100  'Meal, Soybean
  COMAGGR    TOTMEAL  + 0813200  'Meal, Peanut
  COMAGGR    TOTMEAL  + 0813300  'Meal, Cottonseed
  COMAGGR    TOTMEAL  + 0813500  'Meal, Sunflowerseed
  COMAGGR    TOTMEAL  + 0813600  'Meal, Rapeseed
  COMAGGR    TOTMEAL  + 0813700  'Meal, Copra
  COMAGGR    TOTMEAL  + 0813800  'Meal, Palm Kernel
  COMAGGR    TOTMEAL  + 0814200  'Meal, Fish

! Cotton, bales
  COMAGGR    COTBALE  + 2631000  'Cotton

! Total grains
  COMAGGR    TOTGRNS  + 0430000  'Barley
  COMAGGR    TOTGRNS  + 0440000  'Corn
  COMAGGR    TOTGRNS  + 0451000  'Rye
  COMAGGR    TOTGRNS  + 0452000  'Oats
  COMAGGR    TOTGRNS  + 0459100  'Millet
  COMAGGR    TOTGRNS  + 0459200  'Sorghum
  COMAGGR    TOTGRNS  + 0459900  'Mixed Grains
  COMAGGR    TOTGRNS  + 0410000  'Wheat
  COMAGGR    TOTGRNS  + 0422110  'Rice
! -------    -------  - -------  ......

0 个答案:

没有答案