facet_wrap ( ~ group , scales = "free" ,
labeller = names
#labeller(group = label_facet(df$group, "grouping"))
) +
theme_bw ()
p
}
figure ( new_lst $ NED )
figure <- function ( df ){
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 = "limegreen" ) +
coord_flip () +
labs ( title = "Number of common ID" , 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 )) +
# other 20, NED = 35
scale_x_discrete ( labels = function ( x ) str_wrap ( x , width = 32 )) +
facet_wrap ( ~ group , scales = "free" ,
labeller = names
#labeller(group = label_facet(df$group, "grouping"))
) +
theme_bw ()
p
}
figure ( new_lst $ NED )
figure <- function ( df ){
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 = "limegreen" ) +
coord_flip () +
labs ( title = "Number of common ID" , 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 )) +
# other 20, NED = 35
scale_x_discrete ( labels = function ( x ) str_wrap ( x , width = 35 )) +
facet_wrap ( ~ group , scales = "free" ,
labeller = names
#labeller(group = label_facet(df$group, "grouping"))
) +
theme_bw ()
p
}
figure ( new_lst $ NED )
for ( i in 1 : 28 ){
p <- figure ( new_lst [[ i ]])
ggsave ( plot = p ,
filename = paste0 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 12 , height = 8 )
}
figure <- function ( df ){
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 = "limegreen" ) +
coord_flip () +
labs ( title = "Number of common ID" , 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 )) +
# other 20, NED = 35
scale_x_discrete ( labels = function ( x ) str_wrap ( x , width = 20 )) +
facet_wrap ( ~ group , scales = "free" ,
labeller = names
#labeller(group = label_facet(df$group, "grouping"))
) +
theme_bw ()
p
}
new_lst [[ 1 ]]
names ( new_lst [[ 1 ]])
figure <- function ( 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 = "limegreen" ) +
coord_flip () +
labs ( title = "Number of common ID" , 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 )) +
# other 20, NED = 35
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"))
) +
theme_bw ()
p
}
for ( i in 1 : 28 ){
if ( sheetsnames [ i ] == "NED" ){
p <- figure ( new_lst [[ i ]], 35 )
}
else {
p <- figure ( new_lst [[ i ]], 20 )
}
ggsave ( plot = p ,
filename = paste0 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 12 , height = 8 )
}
NED <- figure ( new_lst $ NED , 35 )
NED <- figure ( new_lst $ NED , 35 )
NED
ggsave ( plot = NED ,
filename = paste0 ( get.data.dir (), "/plots/" , "NED_" , "_plot.png" ),
width = 12 , height = 8 )
ggsave ( plot = NED ,
filename = paste0 ( get.data.dir (), "/plots/" , "NED_" , "_plot.png" ),
width = 15 , height = 8 )
ggsave ( plot = NED ,
filename = paste0 ( get.data.dir (), "/plots/" , "NED_" , "_plot.png" ),
width = 18 , height = 8 )
for ( i in 1 : 28 ){
if ( sheetsnames [ i ] == "NED" ){
p <- figure ( new_lst [[ i ]], 35 )
}
else {
p <- figure ( new_lst [[ i ]], 20 )
}
ggsave ( plot = p ,
filename = paste0 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
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 = "limegreen" ) +
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 )) +
# other 20, NED = 35
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"))
) +
theme_bw ()
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 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
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 = "limegreen" ) +
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 )) +
# other 20, NED = 35
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 ( "Plot of the number of common ID for country: " , country )) +
ggeasy :: easy_center_title () +
theme_bw ()
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 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
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 = "limegreen" ) +
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 )) +
# other 20, NED = 35
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 ( "Plot of the number of common ID for country: " , country )) +
theme_update ( plot.title = element_text ( hjust = 0.5 )) +
theme_bw ()
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 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
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 = "limegreen" ) +
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 )) +
# other 20, NED = 35
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 ( "Plot of the number of common ID for country: " , country )) +
theme ( plot.title = element_text ( hjust = 0.5 )) +
theme_bw ()
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 ( get.data.dir (), "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
getwd ()
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" , "/plots/" , sheetsnames [ i ] , "_plot.png" ),
width = 18 , height = 8 )
}
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 )
}
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 <- 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 = "limegreen" ) +
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 )) +
# other 20, NED = 35
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"))
) +
guides ( fill = FALSE ) +
ggtitle ( paste0 ( "Plot of the number of common ID for country: " , country )) +
theme ( plot.title = element_text ( hjust = 0.5 )) +
theme_bw ()
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 )
}
new_lst $ BEL
figure ( "BEL" , new_lst $ BEL , 35 )
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 )) +
# other 20, NED = 35
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 ( "Plot of the number of common ID for country: " , country )) +
theme ( plot.title = element_text ( hjust = 0.5 )) +
theme_bw ()
p
}
figure ( "BEL" , new_lst $ BEL , 35 )
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 )) +
# other 20, NED = 35
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 ( plot.title = element_text ( hjust = 0.5 )) +
theme_bw ()
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 <- 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
}
figure ( "BEL" , new_lst $ BEL , 35 )
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 )
}
knitr :: opts_chunk $ set ( echo = TRUE )
summary ( cars )
plot ( pressure )
View ( pressure )
knitr :: opts_chunk $ set ( echo = TRUE )
file_names <- list.files ( "D:/public/data/fadn/lieferung_20210414/csv" , include.dirs = TRUE )
file_names_gpg <- file_names [ grepl ( ".gpg" , file_names )]
length ( file_names_gpg )
file_names <- file_names [ ! grepl ( ".gpg" , file_names )]
library ( tidyverse )
file_names <- file_names %>% tibble ( name = . ) %>% mutate ( country = str_sub ( name , 1 , 3 ), year = str_sub ( name , 4 , 7 ))
file_names %>% print ( n = 30 )
file_names %>% group_by ( year ) %>% count ()
file_names %>% filter ( country == "POL" )
file_names <- file_names %>% mutate ( provided = "y" )
data_requested_general <- read_xlsx ( path = "D:/public/data/fadn/lieferung_20210414/FADN data request forms_March2021_MM210326.xlsx" , sheet = 2 , range = "A365:P393" )
library ( tidyverse )
library ( readxl )
library ( data.table )
data_requested_general <- read_xlsx ( path = "D:/public/data/fadn/lieferung_20210414/FADN data request forms_March2021_MM210326.xlsx" , sheet = 2 , range = "A365:P393" )
colnames ( data_requested_general )[ 1 ] <- "country"
data_requested_general <- data_requested_general %>% mutate ( country = str_sub ( country , 2 , 4 ))
data_requested_general_long <- data_requested_general %>% pivot_longer ( - country )
data_requested_general_long <- data_requested_general_long %>% filter ( value == "y" ) %>% rename ( year = name , requested = value )
requested_and_provided <- data_requested_general_long %>% full_join ( file_names %>% select ( - name ), by = c ( "country" , "year" )) %>% filter ( is.na ( requested ) | is.na ( provided ))
## if empty, than everything is fine
requested_and_provided
# writexl::write_xlsx(x=requested_and_provided,path="D:/public/data/fadn/lieferung_20210414/missing_countries_years.xlsx")
files_list <- list ()
folder_csv <- "D:/public/data/fadn/lieferung_20210414/csv/"
system.time ({
files_list <- lapply ( file_names %>% pull ( name ) %>% unique (), function ( x ) fread ( input = paste0 ( folder_csv , x )))
}) ## 41.16 ~ 76 sec
files <- rbindlist ( files_list )
files %>% select ( YEAR , COUNTRY , countryyear )
## Number of sum of sample farms - observation - not unique
files %>% select ( YEAR , COUNTRY ) %>% group_by ( COUNTRY ) %>% count () %>% print ( n = 28 )
## Combination of country and year in data set
files %>% select ( YEAR , COUNTRY ) %>% group_by ( COUNTRY ) %>% distinct ()
library ( fadnUtils )
library ( fadnUtils )
library ( fadnUtils )
library ( fadnUtils )
library ( fadnUtils )
library ( fadnUtils )
devtools :: load_all ( "." )
knitr :: opts_chunk $ set ( echo = TRUE )
library ( tidyverse )
library ( readxl )
library ( data.table )
library ( skimr )
file_names <- list.files ( "D:/public/data/fadn/lieferung_20210414/csv" , include.dirs = TRUE )
file_names_gpg <- file_names [ grepl ( ".gpg" , file_names )]
length ( file_names_gpg )
file_names <- file_names [ ! grepl ( ".gpg" , file_names )]
library ( tidyverse )
file_names <- file_names %>% tibble ( name = . ) %>% mutate ( country = str_sub ( name , 1 , 3 ), year = str_sub ( name , 4 , 7 ))
file_names %>% print ( n = 30 )
file_names %>% group_by ( year ) %>% count ()
file_names %>% filter ( country == "POL" )
file_names <- file_names %>% mutate ( provided = "y" )
data_requested_general <- read_xlsx ( path = "D:/public/data/fadn/lieferung_20210414/FADN data request forms_March2021_MM210326.xlsx" , sheet = 2 , range = "A365:P393" )
colnames ( data_requested_general )[ 1 ] <- "country"
data_requested_general <- data_requested_general %>% mutate ( country = str_sub ( country , 2 , 4 ))
data_requested_general_long <- data_requested_general %>% pivot_longer ( - country )
data_requested_general_long <- data_requested_general_long %>% filter ( value == "y" ) %>% rename ( year = name , requested = value )
requested_and_provided <- data_requested_general_long %>% full_join ( file_names %>% select ( - name ), by = c ( "country" , "year" )) %>% filter ( is.na ( requested ) | is.na ( provided ))
## if empty, than everything is fine
requested_and_provided
# writexl::write_xlsx(x=requested_and_provided,path="D:/public/data/fadn/lieferung_20210414/missing_countries_years.xlsx")