Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#+eval=FALSE
#...................................................................................#
#
# USE CASE 1 example
#
# Import csv FADN data
#
#...................................................................................#
# In order to use fadnUtils, we must load fadnUtils and data.table
library(fadnUtils)
library(data.table)
# .............. CREATE data.dir ...................................................#
# fadnUtils always work with a user defined data.dir
# Let's assume that the user has not created one yet.
# The following line creates a data.dir folder somewhere in our computer
# We must also have created the raw_str_map.file and pass it as an argument
# to the function. This file is copied to the data.dir folder. Thus, we can
# see the structure of the data contained in a data.dir folder by inspecting
# the raw_str_map.file residing in it.
create.data.dir(
folder.path = "H:/IFM-CAP/sample.fadnutils.dir",
raw_str_map.file = "H:/IFM-CAP/version2/data/raw_str_map.after2013_var_names.json"
)
#Once the data.dir is created, we must declare that we are working with it
set.data.dir(
"H:/IFM-CAP/sample.fadnutils.dir"
)
# .............. IMPORT DATA IN A SINGLE STEP ......................................#
# In order to import the FADN csv files, the simplest way is
# to use import.fadn.csv.
# We provide the full path of the csv file and explicitly state
# the country and the year this file is refering to.
# Using this function, both the csv data is saved in r-data format and the
# structured r-data are created using the data.dir raw_str_map.file
import.fadn.csv(
file.path = "H:/IFM-CAP/dg_agri_csv/ELL2007.csv", #full path of the cvs file
fadn.country = "ELL",
fadn.year = 2007
)
# We can import many files (countries, years) in a single data.dir
import.fadn.csv(
file.path = "H:/IFM-CAP/dg_agri_csv/ESP2007.csv", #full path of the cvs file
fadn.country = "ESP",
fadn.year = 2007
)
#At any time, we can check for the current data dir, what csv files (countries, year)
# are loaded.
show.data.dir.contents()
# .............. IMPORT DATA IN TWO STEPS ..........................................#
# However you can import the file in two steps, one for converting
# the csv to fadn.raw.str (csv-data to raw r-data) and
# one for converting the fadn.raw.rds to fadn.str.rds (raw r-data
# to structured r-data).
#step 1, convert csv to fadn.raw.rds
convert.to.fadn.raw.rds(
file.path = "H:/IFM-CAP/dg_agri_csv/ELL2015.csv",
fadn.country = "ELL",
fadn.year = 2015
)
# If you check what exists in the data.dir, you will see that
# only the fadn.raw.rds of ELL-2008 exist
show.data.dir.contents()
#Step 2, convert fadn.raw.rds to fadn.str.rds
convert.to.fadn.str.rds(
fadn.country = "ELL",
fadn.year = 2015
)
#check what is loaded
show.data.dir.contents()
# .............. RECALCULATE STRUCTURED DATA ......................................#
# Let's say that
overwrite.raw_str_map.file(
data.dir = "H:/IFM-CAP/sample.fadnutils.dir",
new.raw_str_map.file = "H:/IFM-CAP/version2/data/raw_str_map.after2013_var_names.json"
)