faoebx5.Rmd
The first time you use the faoebx5
package you must set your EBX credentials. In this step your credetials will be sotred in the safe way, for this we have used the keyring
R package. If you would not store your credentials, you should use the function RemoveEBXCredentials()
. In this overview, we show just the functions related to code lists, once the functions about groups work similarly.
Once you have typed your password twice after run SetEBXCredentials()
function, you do not need to rerun this function, because your credential will be kept.
library('faoebx5')
library('dplyr')
SetEBXCredentials(username = "SilvaLu", new = FALSE)
#> OK
#> 0
This function aimed to get the list of code list available in the EBX5. It has two arguments: branch
and instance
that default values are set as “Fishery”.
ebx_cl <- GetEBXCodeLists()
head(ebx_cl)
This function aimed to read code list data from EBX5 to R. As we can see,
cl_fao_level1 <- ReadEBXCodeList(sdmx_name = 'CL_FI_COMMODITY_FAO_LEVEL1')
cl_fao_level1 %>% tbl_df()
#> # A tibble: 4 x 5
#> Identifier FAO_Code NameEn NameFr NameEs
#> <fct> <fct> <fct> <fct> <fct>
#> 1 50001 1 Fish Poissons Peces
#> 2 50064 2 Crustaceans Crustacés Crustáceos
#> 3 50086 5 Molluscs, aquatic inver~ Mollusques, autres inve~ Moluscos y otros inver~
#> 4 50114 7 Fish, crustaceans, moll~ Poissons, crustacés, mo~ Peces, crustáceos, mol~
Please, be aware that the next two functions can modify the original data. Anyway, we should have rights to do changes in the original data.
InsertEBXCodeList()
and UpdateEBXCodeList()
should be used carefully, because it will change the original data stored in the EBX database. Regardless, this function only can be run by users who are rights to insert and update data in the EBX.
Currently, faoebx5
has not implemmented function to remove data in the EBX, so we can do it only using the EBX user interface.
The InsertEBXCodeList()
function requires a data frame with the new rows that will be inserted. This data frame must contain the same variables/columns of the original table. For instance, the code list FAO_Level1
has the following columns: Identifier, FAO_Code, NameEn, NameFr, NameEs. Therefore, the new rows will contain these same columns, as we can see in the data frame cl_faolevel1_new
.
cl_faolevel1_new <- data.frame(
Identifier = 99999,
FAO_Code = 7L,
NameEn = "XXXX_English",
NameFr = "XXXX_French",
NameEs = "XXXX_Es"
)
cl_faolevel1_new
#> Identifier FAO_Code NameEn NameFr NameEs
#> 1 99999 7 XXXX_English XXXX_French XXXX_Es
Once we have created the data frame with the new rows, the next step is to run the function InsertEBXCodeList()
specificating the arguments: data
with data frame composed by the news rows to be inserted, cl_name
the code list name, folder
the folder name, branch
the branch name, and instance
the instance name.
all(names(cl_faolevel1_new) == names(cl_fao_level1))
InsertEBXCodeList(data = cl_faolevel1_new,
cl_name = 'FAO_Level1',
folder = 'Commodity',
branch = 'Fishery',
instance = 'Fishery')
cl_fao_level1 <- ReadEBXCodeList(cl_name = 'FAO_Level1 ')
cl_fao_level1 %>% tbl_df()
UpdateEBXCodeList()
function works similarly to InsertEBXCodeList()
. Therefore, we have to create a data frame with the data that we desire to update and then specify the code list name, as well as the folder
name, branch
name, and the instance
name. In this example, we just changed the data stored in the column NameEs
from XXXX_Es
to Name spanish
.
cl_update <- cl_faolevel1_new
cl_update <- cl_update %>%
mutate(NameEs = 'Name spanish')
UpdateEBXCodeList(data = cl_update,
cl_name = 'FAO_Level1',
folder = 'Commodity',
branch = 'Fishery',
instance = 'Fishery')
cl_fao_level1 <- ReadEBXCodeList(cl_name = 'FAO_Level1 ')
cl_fao_level1 %>% tbl_df()