Skip to content

properly reformatting WIEWS field in MCPD format

@slgora

the code below has changes compared to the original, I see you were trying to address the different format of some of WIEWS fields, but I think this is not the right way do it,

please revert this part to the original code , I'll post below how instead to address the issue

WIEWS_new15crops$SAMPSTAT <- as.numeric(WIEWS_new15crops$SAMPSTAT) #format SAMPSTAT
Genesys_new15crops$SAMPSTAT <- as.numeric(Genesys_new15crops$SAMPSTAT)
WIEWS_new15crops <- WIEWS_new15crops %>%   #format geo data 
  rename(DECLONGITUDE_origin = DECLONGITUDE,
         DECLATITUDE_origin  = DECLATITUDE) %>%
  mutate(DECLONGITUDE = suppressWarnings(as.numeric(DECLONGITUDE_origin)),
         DECLATITUDE  = suppressWarnings(as.numeric(DECLATITUDE_origin)))
Genesys_new15crops <- Genesys_new15crops %>%   #format geo data
  rename(DECLONGITUDE_origin = DECLONGITUDE,
         DECLATITUDE_origin  = DECLATITUDE) %>%
  mutate(DECLONGITUDE = suppressWarnings(as.numeric(DECLONGITUDE_origin)),
         DECLATITUDE  = suppressWarnings(as.numeric(DECLATITUDE_origin)))
Genesys_new15crops$DECLONGITUDE_origin <- as.character(Genesys_new15crops$DECLONGITUDE_origin) #keep origin fields in case of format error
WIEWS_new15crops$DECLONGITUDE_origin  <- as.character(WIEWS_new15crops$DECLONGITUDE_origin)
Genesys_new15crops$DECLATITUDE_origin <- as.character(Genesys_new15crops$DECLATITUDE_origin) #keep origin fields in case format error
WIEWS_new15crops$DECLATITUDE_origin  <- as.character(WIEWS_new15crops$DECLATITUDE_origin)
Genesys_new15crops$COLLSRC <- as.character(Genesys_new15crops$COLLSRC)  #format COLLSRC
WIEWS_new15crops$COLLSRC  <- as.character(WIEWS_new15crops$COLLSRC)

instead after line 118 (WIEWS_new15crops <- WIEWS_new15crops %>% mutate(data_source = "WIEWS")) add the following code:

WIEWS_new15crops$SAMPSTAT <- as.numeric(substr(WIEWS_new15crops$SAMPSTAT, 1, 3)) # convert SAMPSTAT in MCPD standard
WIEWS_new15crops$COLLSRC <- as.numeric(substr(WIEWS_new15crops$COLLSRC, 1, 2))  # convert COLLSRC following MCPD standard
# convert STORAGE in MCPD format
WIEWS_new15crops$STORAGE <- sapply(
  str_extract_all(WIEWS_new15crops$STORAGE, "\\d+(?=\\))"),
  function(x) paste(x, collapse = ";"))

please note Genesys fields are already in MCPD standard there is no need for you to change them as you did