% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{Modes}
\alias{Modes}
\title{Retrieve mode of vector}
\usage{
Modes(x)
Modes(x)
}
\arguments{
\item{x}{vector from which to retrieve the mode from.}
}
\value{
same class as 'x'.
same class as 'x'.
}
\description{
This function returns the mode of a vector. If the vector contains a character or factor, the most common character/factor is returned. Numbers written as characters will be compatible with non-character numbers (i.e. doubles/numeric), but the function returns a character.
This function returns the mode of a vector. If the vector contains a character or factor, the most common character/factor is returned. Numbers written as characters will be compatible with non-character numbers (i.e. doubles/numeric), but the function returns a character.
}
\examples{
Modes(x = c(1, 1, 3, 0, 2, 4, 2, 1, 5, 2, 1))
Modes(x = c('a','b', 'c', 'a', 'c', 'a'))
Modes(x = c('a', 2, 'x', 7895, 1, '2', 't', 2, 1))
Modes(x = c(1, 1, 3, 0, 2, 4, 2, 1, 5, 2, 1))
Modes(x = c('a','b', 'c', 'a', 'c', 'a'))
Modes(x = c('a', 2, 'x', 7895, 1, '2', 't', 2, 1))
}
\seealso{
[tabulate()]
[tabulate()]
}
man/abs_diff.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{abs_diff}
\alias{abs_diff}
\title{Calculates the absolute difference of the reference and the scenarios in a new column}
\usage{
abs_diff(data, vars_to_diff)
}
\arguments{
\item{data}{A dataframe}
\item{vars_to_diff}{A vector with the names of the variables to calculate the difference}
}
\value{
A dataframe with the new columns
}
\description{
Calculates the absolute difference of the reference and the scenarios in a new column
}
man/fadn2fd.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import_fadn.R
\name{fadn2fd}
\alias{fadn2fd}
\title{`fadn2fd()` imports the FADN data from the csv files}
\usage{
fadn2fd(
fadn_data,
mapping,
farmbranch = c("arable", "dairy"),
save_gdx = FALSE
)
}
\arguments{
\item{fadn_data}{FADN}
\item{mapping}{A vector with the names of the columns to be mapped}
\item{farmbranch}{Either arable or dairy}
\item{save_gdx}{Logical. If TRUE, it saves to gdx files}
}
\value{
A list of dataframes with the FADN data
}
\description{
`fadn2fd()` imports the FADN data from the csv files
}
man/fd_desc.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{fd_desc}
\alias{fd_desc}
\title{`fd_desc()` calculates the descriptive statistics of the farm data}
\usage{
fd_desc(farm_data, type = c("arable", "dairy"), csv = FALSE, dir = NULL)
}
\arguments{
\item{farm_data}{A dataframe with the p_farmData}
\item{type}{Type of farm data to analyse (Dairy or Arable farms)}
\item{csv}{Logical. If TRUE, it saves the results as a csv}
}
\value{
A dataframe with the descriptive statistics
}
\description{
`fd_desc()` calculates the descriptive statistics of the farm data
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{first_match_col}
\alias{first_match_col}
\title{`first_match_col()` finds the first matching column in a dataframe}
\usage{
first_match_col(x, pattern, how = c("all", "any"))
}
\arguments{
\item{x}{A dataframe}
\item{pattern}{A pattern to match}
\item{how}{How to match the pattern (all or any)}
}
\value{
The name of the first matching column
}
\description{
`first_match_col()` finds the first matching column in a dataframe
}
\examples{
data <- data.frame(a = c("a", "b", "c"), b = c("a", " ", "c"), c = c("a", "b", "1"))
first_match_col(data, "\\\\D", "all")
first_match_col(data, "\\\\d", "any")
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{gdxbinwider}
\alias{gdxbinwider}
\title{Join BIN data together, make joined dataset wider, and group by a mapping}
\usage{
gdxbinwider(filename, BINDir, gdxmap, mapping)
gdxbinwider(filename, BINDir, gdxmap, mapping)
}
\arguments{
......@@ -16,9 +18,14 @@ gdxbinwider(filename, BINDir, gdxmap, mapping)
\item{mapping}{Column name of the characteristic/variable to be grouped by (e.g. "Regions" or "Regs")}
}
\value{
A tibble `tbl_df`.
A tibble `tbl_df`.
}
\description{
The `gdxbinwider()` function takes in a GDX file with BIN data as parameters p_farmData_NL and p_farmData2GUI, and a mapping as a set.
Then the data is widened, and the output is a tibble.
The `gdxbinwider()` function takes in a GDX file with BIN data as parameters p_farmData_NL and p_farmData2GUI, and a mapping as a set.
Then the data is widened, and the output is a tibble.
}
......@@ -26,8 +33,17 @@ Then the data is widened, and the output is a tibble.
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
gdxbinwider(datafile, BINDir, 'map2binid', 'mapping')
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
gdxbinwider(datafile, BINDir, 'map2binid', 'mapping')
}
\seealso{
\itemize{
\item{\code{\link[gdxrrw]{rgdx.param}}}{Load GDX parameters}
\item{\code{\link[gdxrrw]{rgdx.set}}}{Load GDX sets}
\item{\code{\link[tidyr]{pivot_wider}}}{Make dataframes wider}
}
\itemize{
\item{\code{\link[gdxrrw]{rgdx.param}}}{Load GDX parameters}
\item{\code{\link[gdxrrw]{rgdx.set}}}{Load GDX sets}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{gdxload}
\alias{gdxload}
\title{Load from GDX}
\usage{
gdxload(
filename,
symbol = c("set", "param", "scalar"),
symName,
names = NULL,
...
)
gdxload(
filename,
symbol = c("set", "param", "scalar"),
......@@ -24,12 +32,20 @@ gdxload(
\item{...}{Arguments to be passed to gdxrrw::rgdx(...)}
}
\value{
A dataframe
A dataframe
}
\description{
`gdxload()` is a wrapper for gdxrrw::rgdx. It fixes the issue of having all UELs as factor levels for variables for which they do not belong.
`gdxload()` is a wrapper for gdxrrw::rgdx. It fixes the issue of having all UELs as factor levels for variables for which they do not belong.
}
\seealso{
*gdxrrw::rgdx.set()
*gdxrrw::rgdx.param()
*gdxrrw::rgdx.scalar()
*gdxrrw::rgdx.set()
*gdxrrw::rgdx.param()
*gdxrrw::rgdx.scalar()
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{gdxreshape}
\alias{gdxreshape}
\title{Reshape from wide to long and save to GDX}
\usage{
gdxreshape(
inDF,
symDim,
symName = NULL,
tName = "time",
gdxName = NULL,
setsToo = TRUE,
order = NULL,
setNames = NULL
)
gdxreshape(
inDF,
symDim,
......@@ -33,9 +44,14 @@ gdxreshape(
\item{setNames}{wide dataframe.}
}
\value{
A tibble `tbl_df`.
A tibble `tbl_df`.
}
\description{
`gdxreshape()` formats the data to be saved in GDX into long format. It is imported from the gdxrrw package with a few improvements for performance and usability, since there is a risk of it being removed from the gdxrrw package in the future.
We would like to thank the R GAMS team for this useful function.
`gdxreshape()` formats the data to be saved in GDX into long format. It is imported from the gdxrrw package with a few improvements for performance and usability, since there is a risk of it being removed from the gdxrrw package in the future.
We would like to thank the R GAMS team for this useful function.
}
......@@ -43,8 +59,18 @@ We would like to thank the R GAMS team for this useful function.
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
gdxbinwider(datafile, BINDir, 'map2binid', 'mapping')
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
gdxbinwider(datafile, BINDir, 'map2binid', 'mapping')
}
\seealso{
\itemize{
\item{\code{\link[gdxrrw]{wgdx]}}}{Write R data to GDX}
\item{\code{\link[gdxrrw]{wgdx.lst]}}}{Write multiple symbols to GDX}
\item{\code{\link[gdxrrw]{wgdx.reshape]}}}{Write multiple symbols to GDX}
\item{\code{\link[tidyr]{pivot_longer]}}}{Make dataframes longer}
}
\itemize{
\item{\code{\link[gdxrrw]{wgdx]}}}{Write R data to GDX}
\item{\code{\link[gdxrrw]{wgdx.lst]}}}{Write multiple symbols to GDX}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{groupstats}
\alias{groupstats}
\title{Generate descriptive statistics and save to GDX}
\usage{
groupstats(
filename,
BINDir,
gdxmap,
mapping,
cols,
w,
writegdx = TRUE,
filtern = FALSE
)
groupstats(
filename,
BINDir,
......@@ -33,9 +44,15 @@ groupstats(
\item{filtern}{Logical. If `TRUE`, results will be limited to more than 15 observations per variable for reporting}
}
\value{
A tibble `tbl_df`.
A tibble `tbl_df`.
}
\description{
`groupstats()` returns descriptive statistics per group based on the mapping given. For example, if your mapping
is 'regions', this function will give you the weighted mean, median, min, max, number of observations per variable for each
region based on the individual farm data. When `writegdx` is `TRUE`, it writes the GDX in the format 'farmStats_(mapping).gdx'
`groupstats()` returns descriptive statistics per group based on the mapping given. For example, if your mapping
is 'regions', this function will give you the weighted mean, median, min, max, number of observations per variable for each
region based on the individual farm data. When `writegdx` is `TRUE`, it writes the GDX in the format 'farmStats_(mapping).gdx'
......@@ -43,6 +60,14 @@ region based on the individual farm data. When `writegdx` is `TRUE`, it writes t
\examples{
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
groupstats('FarmDynRexampledata.gdx',
BINDir="inst/extdata/GAMS/",
gdxmap = 'map2binid',
mapping = 'mapping',
cols = c('a', 'b'),
w='Weight')
BINDir <- "inst/extdata/GAMS"
datafile <- 'FarmDynRexampledata.gdx'
groupstats('FarmDynRexampledata.gdx',
BINDir="inst/extdata/GAMS/",
gdxmap = 'map2binid',
......@@ -51,6 +76,14 @@ groupstats('FarmDynRexampledata.gdx',
w='Weight')
}
\seealso{
\itemize{
\item{\code{\link{summary]}}}{summary statistics}
\item{\code{\link[psych]{describe}}}{Descriptive statistics}
\item{\code{\link[gdxrrw]{wgdx}}}{Write R data to GDX}
\item{\code{\link[gdxrrw]{wgdx.lst}}}{Write multiple symbols to GDX}
\item{\code{\link[tidyr]{pivot_longer}}}{Make dataframes longer}
}
\itemize{
\item{\code{\link{summary]}}}{summary statistics}
\item{\code{\link[psych]{describe}}}{Descriptive statistics}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{is.nan.data.frame}
\alias{is.nan.data.frame}
\title{`is.nan.data.frame()` checks if there are any NaNs in a dataframe (`is.nan()` does not work for dfs)}
\usage{
\method{is.nan}{data.frame}(x)
}
\arguments{
\item{x}{A dataframe}
}
\value{
A dataframe with TRUE or FALSE for each column
}
\description{
`is.nan.data.frame()` checks if there are any NaNs in a dataframe (`is.nan()` does not work for dfs)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{load_dump_marg}
\alias{load_dump_marg}
\title{`load_dump_marg()` loads any marginal from the dump gdx files}
\usage{
load_dump_marg(res_fold, scen_name, marginal)
}
\arguments{
\item{res_fold}{Path to the folder where the gdx files are}
\item{scen_name}{Name of the scenarios to load}
\item{marginal}{Name of the marginal to load}
}
\value{
A data.table with the marginal
}
\description{
`load_dump_marg()` loads any marginal from the dump gdx files
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{load_dump_par}
\alias{load_dump_par}
\title{`load_dump_par()` loads any parameter from the dump gdx files}
\usage{
load_dump_par(res_fold, scen_name, param, names = NULL)
}
\arguments{
\item{res_fold}{Path to the folder where the gdx files are}
\item{scen_name}{Name of the scenarios to load}
\item{param}{Name of the parameter to load}
\item{names}{Names of the columns to load}
}
\value{
A data.table with the parameters
}
\description{
`load_dump_par()` loads any parameter from the dump gdx files
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{load_dump_scalar}
\alias{load_dump_scalar}
\title{`load_dump_scalar()` loads any scalar from the dump gdx files}
\usage{
load_dump_scalar(res_fold, scen_name, scalar)
}
\arguments{
\item{res_fold}{Path to the folder where the gdx files are}
\item{scen_name}{Name of the scenarios to load}
\item{scalar}{Name of the scalar to load}
}
\value{
A data.table with the scalar
}
\description{
`load_dump_scalar()` loads any scalar from the dump gdx files
}
\examples{
load_dump_scalar(res_fold = res_fold, scen_name = scen_name, scalar = "p_Nmin")
}
man/load_dumps.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{load_dumps}
\alias{load_dumps}
\title{`load_dumps()` loads the p_res from the dump gdx files}
\usage{
load_dumps(res_fold, scen_name)
}
\arguments{
\item{res_fold}{Path to the folder where the gdx files are}
\item{scen_name}{Name of the scenarios to load}
}
\value{
A data.table with the parameters
}
\description{
`load_dumps()` loads the p_res from the dump gdx files
}
man/pipe.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-pipe.R
\name{\%>\%}
\alias{\%>\%}
\title{Pipe operator}
\usage{
lhs \%>\% rhs
}
\arguments{
\item{lhs}{A value or the magrittr placeholder.}
\item{rhs}{A function call using the magrittr semantics.}
}
\value{
The result of calling `rhs(lhs)`.
}
\description{
See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
}
\keyword{internal}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{replace_first_match_col}
\alias{replace_first_match_col}
\title{`replace_first_match_col()` replaces the name of the column in `first_match_col()` with what the user inputs}
\usage{
replace_first_match_col(x, pattern, how = c("all", "any"), replace_with)
}
\arguments{
\item{x}{A dataframe}
\item{pattern}{A pattern to match}
\item{how}{How to match the pattern (all or any)}
\item{replace_with}{The name to replace the column name with}
}
\value{
dataframe with the replaced column name
}
\description{
`replace_first_match_col()` replaces the name of the column in `first_match_col()` with what the user inputs
}
\examples{
data <- data.frame(a = c("a", "b", "c"), b = c("a", " ", "c"), c = c("a", "b", "1"))
replace_first_match_col(data, "\\\\D", "all", "new")
replace_first_match_col(data, "\\\\d", "any", "new")
}
man/rgdx.var.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{rgdx.var}
\alias{rgdx.var}
\title{Improved function to load variables from gdx files (from Renger in GAMSWorld forum)}
\usage{
rgdx.var(varname, scen_name, res_fold)
}
\arguments{
\item{varname}{Name of the variable to load}
\item{scen_name}{Name of the scenarios to load}
\item{res_fold}{Path to the folder where the gdx files are}
}
\value{
A data.table with the variable
}
\description{
Improved function to load variables from gdx files (from Renger in GAMSWorld forum)
}
\references{
https://forum.gamsworld.org/viewtopic.php?t=9966
}
man/rm_lown.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{rm_lown}
\alias{rm_lown}
\title{`rm_lown()` removes aggregated farms with less than 15 farms for reporting}
\usage{
rm_lown(data, farm_data)
}
\arguments{
\item{data}{A dataframe with the data to plot}
\item{farm_data}{A dataframe with the farm data}
}
\value{
A dataframe with the data without the aggregated farms
}
\description{
`rm_lown()` removes aggregated farms with less than 15 farms for reporting
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
% Please edit documentation in R/FarmDynR backup.R, R/FarmDynR.R
\name{runFarmDynfromBatch}
\alias{runFarmDynfromBatch}
\title{Execute FarmDyn}
\usage{
runFarmDynfromBatch(FarmDynDir, IniFile, XMLFile, BATCHDir, BATCHFile)
runFarmDynfromBatch(FarmDynDir, IniFile, XMLFile, BATCHDir, BATCHFile)
}
\arguments{
......@@ -18,15 +20,23 @@ runFarmDynfromBatch(FarmDynDir, IniFile, XMLFile, BATCHDir, BATCHFile)
\item{BATCHFile}{Name of the .batch file}
}
\value{
Executes FarmDyn from R
Executes FarmDyn from R
}
\description{
`runFarmDynfromBatch()` does as it says in the function.
`runFarmDynfromBatch()` does as it says in the function.
}
\examples{
TODO write example
TODO write example
}
\seealso{
*Globiom?
*Globiom?
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/FarmDynR.R
\name{scen_analysis}
\alias{scen_analysis}
\title{Data analysis function for repeated tasks
This loads p_res from different scenarios}
\usage{
scen_analysis(res_fold, scen_name)
}
\arguments{
\item{res_fold}{Path to the folder where the gdx files are}
\item{scen_name}{Name of the scenarios to load}
}
\value{
A data.table with the parameters
}
\description{
Data analysis function for repeated tasks
This loads p_res from different scenarios
}