fixing vartable json
This commit is contained in:
parent
aff877602d
commit
a3c46ad623
@ -1,6 +1,6 @@
|
|||||||
Package: RBBGCMuso
|
Package: RBBGCMuso
|
||||||
Title: An R package for BiomeBGC-MuSo ecosystem modelling
|
Title: An R package for Biome-BGCMuSo ecosystem modelling
|
||||||
Version: 0.7.1
|
Version: 1.0.0
|
||||||
Authors@R: person("Roland", "Hollo's", , "hollorol@gmail.com", role = c("aut", "cre"))
|
Authors@R: person("Roland", "Hollo's", , "hollorol@gmail.com", role = c("aut", "cre"))
|
||||||
Description: What the package does (one paragraph).
|
Description: What the package does (one paragraph).
|
||||||
Depends: R (>= 3.3.2)
|
Depends: R (>= 3.3.2)
|
||||||
|
|||||||
@ -10,36 +10,10 @@
|
|||||||
|
|
||||||
updateMusoMapping <- function(excelName, dest="./", version=getOption("RMuso_version")){
|
updateMusoMapping <- function(excelName, dest="./", version=getOption("RMuso_version")){
|
||||||
|
|
||||||
expandRangeRows <- function (ind) {
|
|
||||||
toExpand <- excelDF[ind,]
|
|
||||||
rangeString <- gsub(".*?(\\d*\\-\\d*).*","\\1",toExpand[2])
|
|
||||||
interval <- as.numeric(strsplit(rangeString,split="-")[[1]])
|
|
||||||
result <- do.call(rbind,lapply(interval[1]:interval[2],function(x){
|
|
||||||
toExpand[2] <- x
|
|
||||||
toExpand[1] <- gsub("\\[.*?\\]",sprintf("_%s",(x-interval[1])),toExpand[1])
|
|
||||||
toExpand
|
|
||||||
}))
|
|
||||||
result <- as.data.frame(result,stringsAsFactors = FALSE)
|
|
||||||
result[,2] <- as.numeric(result[,2])
|
|
||||||
colnames(result) <- c("names","codes","units","descriptions")
|
|
||||||
result[,c(2,1,3,4)]
|
|
||||||
}
|
|
||||||
|
|
||||||
excelDF <- read.xlsx(excelName)
|
excelDF <- read.xlsx(excelName)
|
||||||
excelDF <- excelDF[!is.na(excelDF[,2]),]
|
excelDF <- excelDF[!is.na(excelDF[,2]),]
|
||||||
excelDF[,1] <- trimws(excelDF[,1])
|
outMatrix <- excelDF[,c(1,2,5,4)]
|
||||||
excelDF[,2] <- trimws(excelDF[,2])
|
names(outMatrix) <- c("codes","names","units","descriptions")
|
||||||
excelDF[,3] <- trimws(excelDF[,3])
|
|
||||||
excelDF[,4] <- trimws(excelDF[,4])
|
|
||||||
rangeRows <- grep("-",excelDF[,2])
|
|
||||||
nonRangeMatrix <- excelDF[setdiff(1:nrow(excelDF),rangeRows),]
|
|
||||||
nonRangeMatrix[,2] <- as.numeric(nonRangeMatrix[,2])
|
|
||||||
nonRangeMatrix[,1] <- trimws(nonRangeMatrix[,1])
|
|
||||||
names(nonRangeMatrix) <- c("names","codes","units","descriptions")
|
|
||||||
outMatrix <- rbind.data.frame(do.call(rbind.data.frame,lapply(rangeRows,expandRangeRows)),
|
|
||||||
nonRangeMatrix[,c(2,1,3,4)])
|
|
||||||
outMatrix <- outMatrix[order(outMatrix[,1]),]
|
|
||||||
rownames(outMatrix)<- NULL
|
|
||||||
write_json(outMatrix, file.path(dest,sprintf("varTable%s.json",version)), pretty=TRUE)
|
write_json(outMatrix, file.path(dest,sprintf("varTable%s.json",version)), pretty=TRUE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user