% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/check_column_names.R
\name{check_file_type}
\alias{check_file_type}
\title{Check the type of load file}
\usage{
check_file_type(filepath)
}
\arguments{
\item{filepath}{A rds or csv file address.}
}
\value{
A data frame with cases corresponding to lines and variables to fields in the file.
}
\description{
This function checks the type of the load file and read this file.
If the file is not a csv or rds file,
the execution of the currently running R code will be stopped.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/common_id.R
\name{collect.common.id}
\alias{collect.common.id}
\title{Collect Common id}
\usage{
collect.common.id(my.r.data)
}
\arguments{
\item{my.r.data}{A data object(either a data.table or a list).}
}
\value{
A data.table, it includes just one column that named "common_id".
}
\description{
Load the Fadn.raw.rds data (Data Table) or Fadn.str.rds data (List),
then collection the common id from different years on this data.
}
\examples{
collect.common.id(fadn.raw.rds)
## collection the common "id" from the raw rds data
## for 2009-2012 years and country "BEL".
## Return a DT with one column named "common_id".
}
\author{
Xinxin Yang
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convert_data.R
\name{convert.to.fadn.raw.rds}
\alias{convert.to.fadn.raw.rds}
\title{Gets a fadn.raw.csv (csv file from DG-AGRI) and transforms it accordingly to fadn.raw.rds}
\usage{
convert.to.fadn.raw.rds(
file.path = "",
sepS = ",",
fadn.year = NA,
fadn.country = NA,
keep.csv = F,
col.id = "ID"
)
}
\arguments{
\item{file.path}{the full path of the csv file (the filename must be included)}
\item{sepS}{the separator of the csv files (by default ",")}
\item{fadn.year}{the year the csv files refers to (e.g. 2001)}
\item{fadn.country}{the three letter country code the csv files refers to (e.g. "ELL")}
\item{keep.csv}{if TRUE, copy the csv files to the CSV directory; else do not copy}
}
\value{
Saves the fadn.raw.rds file and returns TRUE if everything goes well
}
\description{
It saves two files:
- One that contain a wide format of the data, i.e. in tabular format that is identical to the csv data. This is uncompressed data.
- One that holds the same information in compressed data. It is a list that contains $data.char and $data.num data.tables in long format. 0 values are removed and only the col.id is the index on both data.tables
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convert_data.R
\name{convert.to.fadn.str.rds}
\alias{convert.to.fadn.str.rds}
\title{Converts an fadn.raw.rds file to fadn.str.rds file using a raw_str_map.json file}
\usage{
convert.to.fadn.str.rds(
fadn.country = NA,
fadn.year = NA,
raw_str_map.file = NULL,
force_external_raw_str_map = FALSE,
str.name = NULL,
DEBUG = F
)
}
\arguments{
\item{fadn.country}{string with the country to extract the str data}
\item{fadn.year}{the year to extract the structured data}
\item{raw_str_map.file}{the full path to the raw_str_map file.}
\item{DEBUG}{if TRUE, prints more details on the conversion process}
\item{str.short_name}{the short name of the str data. No spaces and text up to 20 characters}
}
\value{
Saves the rds.str.fadn and returns TRUE if everything goes well
}
\description{
The raw_str_map.json specification is as follows:
}
\details{
{
"id": { "COLUMN in every list member in RDS": "COLUMN IN CSV", ....},
"info": { "COLUMN in info RDS": "COLUMN IN CSV", ....},
"livestock": {}
"crops": {
"CROP NAME 1": {"description": "description of crop name", "columns": {"VARIABLE NAME": COLUMN IN CSV", ....} },
"CROP NAME 2": {"description": "description of crop name", "columns": {"VARIABLE NAME": COLUMN IN CSV", ....} },
....
}
}
The structure of the str.dir:
- A data.dir can hold more than one extractions.
- Each extraction has a short name (20 or less characters, whitespace is not allowed)
- Each extraction is stored in the data.dir/rds/<extraction_name>
- That folder contains the following files:
+ raw_str_map.json: the raw_str_map
+ fadn.str.<4-digit YEAR>.<3-letter COUNTRY>.rds: the extracted data
Notes:
1) The computed RDS file contains a list structure with the following keys: info, costs, livestock-animals and crops
All are data.tables. For all of them, the first columns are those that are contained in the "id" object
"info" and "costs" are in table format, i.e. each farm is one row and data is on columns, as defined in the
related raw_str_map.json file.
"crops" and "livestock-animals" are in wide data format (https://tidyr.tidyverse.org/), where one farm lies accross many rows, and each
row is a farm-crop-variableName-value combination
2) In $id, $info and $costs, "COLUMN IN CSV" can have two forms
i) a single column name in the fadn.raw csv file or a combination, e.g. "K120SA+K120FC+K120FU+K120CV-K120BV"
ii) the form of an object {"source": "the column in the csv", "description": "a description of what this column is about"}
3) We attach certain attributes that are useful for identifying informations:
i) In $info and $costs, the attribute "column description" provide information of the formula and the description of each column
ii) In $crops and $livestock-animals, the attribute "$crops.descriptions" and "$livestock.descriptions", provide the description of each CROP contained there
iii) In $crops and $ the attribute "$column.formulas" provide the formulas used in order to derive the VALUE
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{create.data.dir}
\alias{create.data.dir}
\title{Creates a data.dir}
\usage{
create.data.dir(
folder.path,
metadata = "{\\n'description': 'No Description Provided',\\n'created-by':'',\\n'created-at':''\\n}"
)
}
\arguments{
\item{metadata}{}
}
\value{
TRUE if created succesfully; FALSE otherwise. It return in invisible mode.
}
\description{
Creates a data.dir
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/handle_rds_data.R
\name{delete.fadn.raw}
\alias{delete.fadn.raw}
\title{Title}
\usage{
delete.fadn.raw(countries = NULL, years = NULL)
}
\arguments{
\item{years}{}
}
\value{
}
\description{
Title
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/handle_rds_data.R
\name{delete.fadn.str}
\alias{delete.fadn.str}
\title{Title}
\usage{
delete.fadn.str(countries = c(), years = c())
}
\arguments{
\item{years}{}
}
\value{
}
\description{
Title
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{get.available.fadn.raw.rds}
\alias{get.available.fadn.raw.rds}
\title{Returns the available YEAR-COUNTRY fadn.raw.rds}
\usage{
get.available.fadn.raw.rds(data.dir = NULL)
}
\value{
a DT of the available YEAR-COUNTRY fadn.raw.rds
}
\description{
Returns the available YEAR-COUNTRY fadn.raw.rds
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{get.available.fadn.str.rds}
\alias{get.available.fadn.str.rds}
\title{Returns the available YEAR-COUNTRY fadn.str.rds, for each str.folder}
\usage{
get.available.fadn.str.rds(data.dir = NULL, extract_dir)
}
\arguments{
\item{extract_dir}{The name of the extraction dir}
}
\value{
DT of the available YEAR-COUNTRY fadn.str.rds
}
\description{
Returns the available YEAR-COUNTRY fadn.str.rds, for each str.folder
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{get.data.dir}
\alias{get.data.dir}
\title{Gets the data.dir}
\usage{
get.data.dir()
}
\value{
the value of option("fadnUtils.data.dir")
}
\description{
data.dir is the folder where data is stored
r package will create two subfolders:
csv = location to store the csv files of th DG-AGRI (fadn.raw.csv)
rds = location to store rds files (fadn.raw.rds, fadn.str.rds, etc.)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/standardResults.R
\name{getFormulaResult}
\alias{getFormulaResult}
\title{Aggregates columns for each farms using a formula}
\usage{
getFormulaResult(data, SEdata, formulaString, aggregator = sum, onlyValue = T)
}
\arguments{
\item{data}{a fadn.container, containing all tables}
\item{SEdata}{a data.table of already calculated SE}
\item{formulaString}{The formula String to use for aggregation}
}
\value{
[FID VALUE]
}
\description{
Aggregates columns for each farms using a formula
}
\examples{
#definition of formula SE610+SE615+SE624-SE626
formula=list(add=c("SE610","J830(2)","#289","#267..270"),substract=c("SE626","M632..634(2)"))
list(add=c("#48","#49","#50"),substract=list())
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/handle_rds_data.R
\name{grep.columns.in.raw.rds}
\alias{grep.columns.in.raw.rds}
\title{Grep a pattern into a raw.rds column names}
\usage{
grep.columns.in.raw.rds(pattern, countries = c("all"), years = c("all"))
}
\arguments{
\item{pattern}{a grep-like character pattern. This parameter is passed as is to the grep function}
\item{countries}{a character vector with all the 3-letter codes of the selected countries, e.g. c("ELL", "ESP").
If "all" is included, all available countries are loaded}
\item{years}{a numeric vector with the years selected. If "all" is included, all available years are loa}
\item{show}{if TRUE, the columsn are printed}
}
\value{
Prints the columns and returns them invisibly
}
\description{
Useful for the case where one want to look if there are certain columns present or missing
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convert_data.R
\name{import.fadn.csv}
\alias{import.fadn.csv}
\title{Imports a DG-AGRI csv into fadnUtils}
\usage{
import.fadn.csv(
file.path,
raw.f = NULL,
sepS = ",",
fadn.year = NA,
fadn.country = NA,
keep.csv = F
)
}
\arguments{
\item{file.path}{the full path of the file (the filename must be included)}
\item{raw.f}{the raw_str_map file to use. it must reside inside 'raw_str_maps; folder of the data.dir}
\item{sepS}{the separator of the csv files (by default ",")}
\item{fadn.year}{the year the csv files refers to (e.g. 2001)}
\item{fadn.country}{the three letter country code the csv files refers to (e.g. "ELL")}
\item{keep.csv}{if TRUE, copy the csv files; else do not copy}
}
\description{
It first call the convert.to.fadn.raw.rds and then convert.to.fadn.str.rds
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/handle_rds_data.R
\name{load.fadn.raw.rds}
\alias{load.fadn.raw.rds}
\title{Load all rds.raw.FADN data for selcted years and countries (rbinds them)}
\usage{
load.fadn.raw.rds(
countries = c("all"),
years = c("all"),
col.filter = NULL,
row.filter = NULL
)
}
\arguments{
\item{countries}{a character vector with all the 3-letter codes of the selected countries, e.g. c("ELL", "ESP").
If "all" is included, all available countries are loaded}
\item{years}{a numeric vector with the years selected. If "all" is included, all available years are loaded}
\item{col.filter}{a character vector with the columns to load. If NULL, all columns are loaded. E.g columns=c('ILOTH_VET_V', 'ILVOTH_V','id')}
\item{row.filter}{a string giving an expression that will be evaluated in order to select rows. If NULL, all rows are returned. E.g. filter='TF8==1'}
}
\value{
list( "countries"=> c(<RETURNED COUNTRIES), "years"=>c(<AVAILABLE YEARS) )
}
\description{
It adds two columns: load.YEAR and load.COUNTRY in each row. This can be used to group per year,country the data
}
\examples{
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/handle_rds_data.R
\name{load.fadn.str.rds}
\alias{load.fadn.str.rds}
\title{Load all rds.str.FADN data for seelcted years and countries}
\usage{
load.fadn.str.rds(extraction_dir, countries = c("all"), years = c("all"))
}
\arguments{
\item{countries}{a character vector with all the 3-letter codes of the selected countries, e.g. c("ELL", "ESP").
If "all" is included, all available countries are loaded}
\item{years}{}
\item{str.name}{The extractionname to load data from}
}
\value{
list( "countries"=> c(<RETURNED COUNTRIES), "years"=>c(<AVAILABLE YEARS) )
}
\description{
Load all rds.str.FADN data for seelcted years and countries
}
\examples{
}
man/nested_var.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/check_column_names.R
\name{nested_var}
\alias{nested_var}
\title{Check a objest in the json file}
\usage{
nested_var(var, rds)
}
\arguments{
\item{var}{A object or category of raw json.}
\item{rds}{All variables/column names in fadn.raw.rds file.}
}
\value{
A list of multiple objects. This list combines no machted variables and the modified json for the chosen object/category.
}
\description{
This function checks the node of chosen object/category for the json file and find out the variables
which are in json file but not in fadn.raw data file.
Returning two lists: unmatched variables/column names and modified json.
If unmatched variable exists, this variable will be deleted from the json list.
}
\details{
A json file has 6 parent objects/categories: "id", "info", "costs", "crops", "subsides", "livstock". This function checks all objects inside the parent object.
}
\author{
Xinxin Yang
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raw_str_map.R
\name{raw_str_map.merge}
\alias{raw_str_map.merge}
\title{Merges two raw_str_map files and returns either a list or a file}
\usage{
raw_str_map.merge(
source.raw_str_map.file = NULL,
new.raw_str_map.file = NULL,
return.file = F
)
}
\arguments{
\item{source.raw_str_map.file}{the filename of the source raw_str_map. It must be relative the raw_str_maps of the current data.dir}
\item{new.raw_str_map.file}{the filename of the mask raw_str_map. It will replace any entries of the source file. It must be relative the raw_str_maps of the current data.dir}
\item{return.file}{If set to T, a temporary full file path that contains the merge is returned. Otherwise a list with the contents of the merge is returned}
}
\value{
FALSE in case of problem / if return.file=T, the temporary full path of a file that contains the merged result in json / A list with the contents of the merge if return.file=F
}
\description{
All entries in the new.raw_str_map file replace those on the source.raw_str_map file
}
\details{
Both files must be relative to the current data.dir/raw_str_maps
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{set.data.dir}
\alias{set.data.dir}
\title{Sets the data.dir}
\usage{
set.data.dir(new.data.dir)
}
\arguments{
\item{new.data.dir}{the full path to the folder where the data.dir will be. Ending slash "/" shall not be present}
}
\value{
TRUE if succesfully set the data.dir; FALSE otherwise. Returns in invisible mode.
}
\description{
Sets the data.dir
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/manage_data_dir.R
\name{show.data.dir.contents}
\alias{show.data.dir.contents}
\title{Show the contents of data.dir}
\usage{
show.data.dir.contents(data.dir = NULL, return.list = F)
}
\arguments{
\item{data.dir}{a specific directory to show contents, otherwise it will read the fadnUtils.data.dir}
\item{return.list}{if T, returns a list, otherwise print the results}
}
\value{
}
\description{
Show the contents of data.dir
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raw_str_map.R
\name{take.raw_str_map.columns}
\alias{take.raw_str_map.columns}
\title{Takes $id, $info, $costs objects of a raw_str_map object and create Source-Description pairs}
\usage{
take.raw_str_map.columns(listcontent)
}
\arguments{
\item{listcontent}{}
}
\value{
list(COLUMN-NAME = c(SOURCE=csv column name, DESCRIPTION=description of column), ..... )
}
\description{
Used internally
}