#.................................................................... # #This file includes functions related to handling (loading, saving) # data from raw.rds files or str.rds, # saved in the RDS subdirectory of the data.dir # #.................................................................... #' Load all rds.raw.FADN data for selcted years and countries (rbinds them) #' #' It adds two columns: load.YEAR and load.COUNTRY in each row. This can be used to group per year,country the data #' #' @param 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 #' @param years a numeric vector with the years selected. If "all" is included, all available years are loaded #' @param 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') #' @param 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' #' #' @return list( "countries"=> c(c(length(col.filter.effective)) { warning(paste0("Not all columns were found: ", paste0(col.filter[!names(col.filter)%in%col.filter.effective],collapse=","))) } data.cur=data.cur[,..col.filter.effective] } data.cur[,load.YEAR:=fadn.raw.rds.avail[FILE==f,YEAR] ] data.cur[,load.COUNTRY:=fadn.raw.rds.avail[FILE==f,COUNTRY] ] print(paste0("Loading from ",rds.dir, f)) if(is.null(data.return)) { data.return=data.cur } else { #take care in case some columns do not exist between the rbind-ed datasets data.return=rbindlist(list(data.return,data.cur),fill = T) } } return(data.return) } #' Load all rds.str.FADN data for seelcted years and countries #' #' @param str.name The extractionname to load data from #' @param 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 #' @param years #' #' @return list( "countries"=> c(c(