^.*\.Rproj$
^\.Rproj\.user$
auto_roxygenize_for_build_and_reload="0"
auto_roxygenize_for_build_package="1"
auto_roxygenize_for_check="1"
live_preview_website="1"
makefile_args=""
preview_website="1"
website_output_format="all"
]0;:/c/Users/yang_x/Desktop/new-Version[?25l
yang_x@HPCBW01-BS  ~/Desktop/new-Version[?25h[?25l
]0;:/c/Users/yang_x/Desktop/new-Version[?25l
yang_x@HPCBW01-BS  ~/Desktop/new-Version
$[?25h
\ No newline at end of file
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","caption":"Terminal 1","channel_id":"3536","channel_mode":1,"child_procs":false,"cols":146,"cwd":"","exit_code":15,"handle":"D6E734FE","interaction_mode":2,"max_output_lines":1000,"restarted":true,"rows":22,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/c/Users/yang_x/Desktop/new-Version","track_env":false,"zombie":false}]
\ No newline at end of file
[
]
\ No newline at end of file
{
"debugBreakpointsState" : {
"breakpoints" : [
]
}
}
\ No newline at end of file
{
"path" : "C:/Users/yang_x/Desktop/new-Version",
"sortOrder" : [
{
"ascending" : false,
"columnIndex" : 2
}
]
}
\ No newline at end of file
{
"installOptions" : {
"installDependencies" : true,
"installFromRepository" : true,
"libraryPath" : "C:/Users/yang_x/Documents/R/R-3.6.3/library"
}
}
\ No newline at end of file
{
"activeTab" : 0,
"activeTabSourceWindow1" : 0,
"activeTabSourceWindow2" : 0,
"activeTabSourceWindow3" : 0,
"activeTabSourceWindow4" : 0,
"activeTabSourceWindow5" : 0,
"activeTabSourceWindow6" : 0
}
\ No newline at end of file
{
"sourceWindowGeometry" : {
"w5y6pjlj2xznu" : {
"height" : 582,
"ordinal" : 6,
"width" : 553,
"x" : 17,
"y" : 93
}
}
}
\ No newline at end of file
{
"left" : {
"panelheight" : 784,
"splitterpos" : 399,
"topwindowstate" : "NORMAL",
"windowheight" : 823
},
"right" : {
"panelheight" : 784,
"splitterpos" : 458,
"topwindowstate" : "NORMAL",
"windowheight" : 823
}
}
\ No newline at end of file
{
"TabSet1" : 3,
"TabSet2" : 1,
"TabZoom" : {
}
}
\ No newline at end of file
build-last-errors="[]"
build-last-errors-base-dir="C:/Users/yang_x/Desktop/new-Version/"
build-last-outputs="[{\"output\":\"==> Rcmd.exe INSTALL --no-multiarch --with-keep.source new-Version\\n\\n\",\"type\":0},{\"output\":\"* installing to library 'C:/Users/yang_x/Documents/R/R-3.6.3/library'\\r\\n\",\"type\":1},{\"output\":\"* installing *source* package 'fadnUtils' ...\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** using staged installation\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** R\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** inst\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** byte-compile and prepare package for lazy loading\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** help\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** installing help indices\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\" converting help for package 'fadnUtils'\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\" finding HTML links ...\",\"type\":1},{\"output\":\" analyzeFormula html \",\"type\":1},{\"output\":\" fertig\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" check.column html \\r\\n\",\"type\":1},{\"output\":\" check.data.dir.structure html \\r\\n\",\"type\":1},{\"output\":\" check.raw_str_map html \\r\\n\",\"type\":1},{\"output\":\" check_file_type html \\r\\n\",\"type\":1},{\"output\":\" collect.common.id html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" convert.to.fadn.raw.rds html \\r\\n\",\"type\":1},{\"output\":\" convert.to.fadn.str.rds html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" create.data.dir html \\r\\n\",\"type\":1},{\"output\":\" delete.fadn.raw html \\r\\n\",\"type\":1},{\"output\":\" delete.fadn.str html \\r\\n\",\"type\":1},{\"output\":\" get.available.fadn.raw.rds html \\r\\n\",\"type\":1},{\"output\":\" get.available.fadn.str.rds html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" get.data.dir html \\r\\n\",\"type\":1},{\"output\":\" getFormulaResult html \\r\\n\",\"type\":1},{\"output\":\" grep.columns.in.raw.rds html \\r\\n\",\"type\":1},{\"output\":\" import.fadn.csv html \\r\\n\",\"type\":1},{\"output\":\" load.fadn.raw.rds html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" load.fadn.str.rds html \\r\\n\",\"type\":1},{\"output\":\" nested_var html \\r\\n\",\"type\":1},{\"output\":\" raw_str_map.merge html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" set.data.dir html \\r\\n\",\"type\":1},{\"output\":\" show.data.dir.contents html \\r\\n\",\"type\":1},{\"output\":\" take.raw_str_map.columns html \\r\\n\",\"type\":1},{\"output\":\" update_elements.DT html \",\"type\":1},{\"output\":\"\\r\\n\",\"type\":1},{\"output\":\" write.excel html \\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** building package indices\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** installing vignettes\\r\\n\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from temporary location\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package can be loaded from final location\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** testing if installed package keeps a record of temporary installation path\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"* DONE (fadnUtils)\\r\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:\\n\\nhttps://cran.rstudio.com/bin/windows/Rtools/\\n\\n\",\"type\":2}]"
compile_pdf_state="{\"errors\":[],\"output\":\"\",\"running\":false,\"tab_visible\":false,\"target_file\":\"\"}"
files.monitored-path=""
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOff\":[],\"matchOn\":[]},\"running\":false}"
imageDirtyState="1"
saveActionState="-1"
{"active_set":"","sets":[]}
\ No newline at end of file
{
"collab_server" : "",
"contents" : "",
"created" : 1618920948104.000,
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "38|35|59|0|\n",
"hash" : "3385672932",
"id" : "2EBE2EFC",
"lastKnownWriteTime" : 1618930088,
"last_content_update" : 1618930096578,
"path" : "D:/public/yang/MIND_STEP/plots.R",
"project_path" : null,
"properties" : {
"cursorPosition" : "21,0",
"scrollLine" : "15",
"tempName" : "Untitled1"
},
"relative_order" : 4,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
}
\ No newline at end of file
# plot the common id over the years
path <- "D:/public/yang/MIND_STEP/new_sample/fadn_data_common_id.xlsx"
sheetsnames <- excel_sheets(path)
length(sheetsnames)
lst <- lapply(1:28, function(i) read_excel(path, sheet = i))
lst_test <- Map(function(x, y) {names(x)[1] <- y; x},
lst, sheetsnames)
names(lst_test) <- sheetsnames
new_colnames <- c("Years","Num_id")
new_lst_ = lapply(lst_test, setNames, new_colnames)
###
new_lst = new_lst_
for (i in 1:28){
new_lst[[i]]$Length <- str_count(new_lst[[i]]$Years)
new_lst[[i]]$group <- cut(new_lst[[i]]$Length, breaks=c(1,10,14,18,25,30,35,40,48,55,58,70,Inf))
#new_lst[[i]]$group <- cut(new_lst[[i]]$Length, breaks=c(1,10,14,18,25,30,35,40,48,55,58,70,Inf))
}
label_facet <- function(original_var, custom_name){
lev <- levels(as.factor(original_var))
#lev <- c()
lab <- paste0(custom_name, ": ", lev)
names(lab) <- lev
return(lab)
}
names <- as_labeller(
c(`(1,10]` = "2 years", `(14,18]` = "3 years",`(18,25]` = "4 years",
`(25,30]` = "5 years",`(30,35]` = "6 years", `(35,40]` = "7 years",
`(40,48]` = "8 years", `(48,55]`= "9 years", `(55,58]` = "10 years",
`(58,70]`="11 and 12 years", `(70,Inf]` = "more than 12"))
figure <- function(country, df, n){
p = df %>%
#ggplot( aes(x = reorder(Years, -Num_id) ,y=Num_id))
ggplot( aes(x = Years ,y=Num_id))+
geom_bar( stat="identity", position = position_dodge(width = 0.8),width=0.5, fill = rainbow(n=length(df$Num_id)) ) +
coord_flip()+
#labs(title = paste0("Plot of the Number of common ID for country: ", country ), fill = "Years") +
xlab("Years") +
ylab("Number of common ID") +
geom_text(aes(label=Num_id), vjust=0.5, colour="black", size=3.5)+
theme(axis.text.x=element_text(color = "black", size=6, angle=0, vjust=.8, hjust=0.8)) +
scale_x_discrete(labels = function(x) str_wrap(x, width = n)) +
facet_wrap( ~ group, scales="free",
labeller=names
#labeller(group = label_facet(df$group, "grouping"))
)+
ggtitle(paste0("Number of common ID for country: ", country )) +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5))
p
}
for (i in 1:28){
if (sheetsnames[i] =="NED"){
p <- figure(sheetsnames[i],new_lst[[i]], 35)
}
else{
p <- figure(sheetsnames[i],new_lst[[i]], 20)
}
ggsave(plot = p,
filename = paste0("D:/public/data/fadn/lieferung_20210414/common_id_plots/",sheetsnames[i] ,"_plot.png"),
width = 18, height = 8)
}
figure("BEL",new_lst$BEL, 35)
{
"collab_server" : "",
"contents" : "",
"created" : 1618920953371.000,
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "4084318790",
"id" : "826115CA",
"lastKnownWriteTime" : 1618576754,
"last_content_update" : 1618576754,
"path" : "D:/public/yang/MIND_STEP/FADN_DATA_14042021.R",
"project_path" : null,
"properties" : {
"cursorPosition" : "11,8",
"scrollLine" : "0"
},
"relative_order" : 5,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
}
\ No newline at end of file
library(fadnUtils)
library(writexl)
library(jsonlite)
library(xlsx)
# FADN Data DIR
dir = "D:/public/data/fadn/lieferung_20210414/csv/"
setwd(dir)
# Get all csv file in FADN data dir
csv_files = list.files(path = dir, pattern= "*.csv$")
csv_list = data.frame(csv_files)
colnames(csv_list) = "names"
# split string into two columns at data frame based on "."
df = data.frame(do.call('rbind', strsplit(as.character(csv_list$names),'.',fixed=TRUE)))
df
# split data frame string into 2 columns
df = separate(df, X1, into = c("country", "Year"), sep = 3, remove = FALSE)
table(df$country)
table(df$Year)
countires = unique(df$country)
years = unique(df$Year)
# 28 countries
#
# Get all csv files for country "DEU"
DEU_csv <- grep("^DEU", csv_list$names, value = TRUE)
length(DEU_csv)
#++++++++++++++++++++++++++++
# set a project dir
set.data.dir("D:/public/yang/MIND_STEP/new_sample")
get.data.dir()
# convert CSV into Raw data for DEU
for(file in csv_files) {
print(file)
# convert into data table
country = substr(file, 1, 3)
# extract 4-7 char
year = substr(file, 4, 7)
convert.to.fadn.raw.rds(
file.path = file,
sepS = ",",
fadn.country = country,
fadn.year = year,
col.id = "ID")
}
show.data.dir.contents()
# CONVERT FADN.RAW.RDS TO FADN.STR.RDS
rds.dir = paste0(get.data.dir(),"/rds/")
# set a str name for for saving the str r-data in rds.dir
new.str.name = "DEU"
# set a extraction_dir
dir.create(paste0(rds.dir, new.str.name))
new.extraction.dir = paste0(rds.dir, new.str.name)
# Save the modifed json file
list_vars = check.column(importfilepath = paste0(rds.dir, "fadn.raw.2018.BEL.rds"), # a rds file or a csv file
jsonfile = "D:/public/yang/MIND_STEP/2014_after_copy.json", # a json file
rewrite_json = TRUE, # write a new json file without unmatched variables
extraction_dir = new.extraction.dir # save the new json in extraction_dir
)
#********************************
year_list = c(2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018)
# find all adjacent combinations in a list
myFun <- function(Data) {
A <- lapply(2:(length(Data)-1L), sequence)
B <- lapply(rev(lengths(A))-1L, function(x) c(0, sequence(x)))
unlist(lapply(seq_along(A), function(x) {
lapply(B[[x]], function(y) Data[A[[x]]+y])
}), recursive = FALSE, use.names = FALSE)
}
adjacent_list = myFun(year_list)
adjacent_list[[45]] = year_list
my.data = list()
for (year_items in adjacent_list) {
name = toString(year_items)
print(class(name))
data = load.fadn.raw.rds(countries = "DEU", years = year_items)
my.data[[name]] = data
}
Big.Num.Common.id = list()
for (data_list in 1:length(my.data)){
data = my.data[data_list]
# Retrieving column names
name = names(data)
print("******************************")
colnames(data[[name]])[which( names(data[[name]]) == "ID")] <- "id"
common.id = collect.common.id(data[[name]])
Big.Num.Common.id[[name]] = nrow(common.id)
}
DF = do.call(rbind, Big.Num.Common.id)
DF = data.frame(DF)
DF$Years <- rownames(DF)
colnames(DF) <- "the number of common id"
rownames(DF) <- NULL
write_xlsx(DF, "D:/public/yang/MIND_STEP/new_sample/DEUData_common_id.xlsx")
{
"collab_server" : "",
"contents" : "",
"created" : 1618923649829.000,
"dirty" : false,
"encoding" : "UTF-8",
"folds" : "",
"hash" : "2873001858",
"id" : "9DDA071",
"lastKnownWriteTime" : 1618925586,
"last_content_update" : 1618925586815,
"path" : "C:/Users/yang_x/Desktop/new-Version/R/common_id.R",
"project_path" : "R/common_id.R",
"properties" : {
"cursorPosition" : "20,0",
"scrollLine" : "12"
},
"relative_order" : 6,
"source_on_save" : false,
"source_window" : "",
"type" : "r_source"
}
\ No newline at end of file