# \donttest{
##### Readymade dataset by GET. Works for readymade datasets and "saved-JSON-stat-query-links".
x <- ApiData("https://data.ssb.no/api/v0/dataset/1066.json?lang=en", getDataByGET = TRUE)
x[[1]] # The label version of the data set
x[[2]] # The id version of the data set
names(x)
comment(x)
##### As above with single data set output
url <- "https://data.ssb.no/api/v0/dataset/1066.json?lang=en"
x1 <- ApiData1(url, getDataByGET = TRUE) # as x[[1]]
x2 <- ApiData2(url, getDataByGET = TRUE) # as x[[2]]
ApiData12(url, getDataByGET = TRUE) # Combined
##### Special output
ApiData("https://data.ssb.no/api/v0/en/table/11419", returnMetaData = TRUE) # meta data
ApiData("https://data.ssb.no/api/v0/en/table/11419", returnMetaValues = TRUE) # meta data values
ApiData("https://data.ssb.no/api/v0/en/table/11419", returnMetaFrames = TRUE) # list of data frames
ApiData("https://data.ssb.no/api/v0/en/table/11419", returnApiQuery = TRUE) # query using defaults
##### Ordinary use (makeNAstatus is in use in first two examples)
# NACE2007 as imaginary value (top 10), ContentsCode as TRUE (all), Tid is default
x <- ApiData("https://data.ssb.no/api/v0/en/table/11419", NACE2007 = 10i, ContentsCode = TRUE)
# Two specified and the last is default (as above) - in Norwegian change en to no in url
x <- ApiData("https://data.ssb.no/api/v0/no/table/11419", NACE2007 = 10i, ContentsCode = TRUE)
# Number of residents (bosatte) last year, each region
x <- ApiData("https://data.ssb.no/api/v0/en/table/04861", Region = TRUE,
ContentsCode = "Bosatte", Tid = 1i)
# Number of residents (bosatte) each year, total
ApiData("https://data.ssb.no/api/v0/en/table/04861", Region = FALSE,
ContentsCode = "Bosatte", Tid = TRUE)
# Some years
ApiData("https://data.ssb.no/api/v0/en/table/04861", Region = FALSE,
ContentsCode = "Bosatte", Tid = c(1, 5, -1))
# Two selected regions
ApiData("https://data.ssb.no/api/v0/en/table/04861", Region = c("1103", "0301"),
ContentsCode = 2, Tid = c(1, -1))
##### Using id instead of url, unnamed input and verbosePrint
ApiData(4861, c("1103", "0301"), 1, c(1, -1)) # same as below
ApiData(4861, Region = c("1103", "0301"), ContentsCode=2, Tid=c(1, -1))
names(ApiData(4861,returnMetaFrames = TRUE)) # these names from metadata assumed two lines above
ApiData("4861", c("1103", "0301"), 1, c(1, -1), urlType="SSBen")
ApiData("01222", c("1103", "0301"), c(4, 9:11), 2i, verbosePrint = TRUE)
ApiData(1066, getDataByGET = TRUE, urlType="SSB")
ApiData(1066, getDataByGET = TRUE, urlType="SSBen")
# }
##### Advanced use using list. See details above. Try returnApiQuery=TRUE on the same examples.
ApiData(4861, Region = list("03*"), ContentsCode = 1, Tid = 5i) # "all" can be dropped from the list
ApiData(4861, Region = list("all", "03*"), ContentsCode = 1, Tid = 5i) # same as above
ApiData(04861, Region = list("item", c("1103", "0301")), ContentsCode = 1, Tid = 5i)
##### Using data from SCB to illustrate returnMetaFrames
urlSCB <- "https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy"
mf <- ApiData(urlSCB, returnMetaFrames = TRUE)
names(mf) # All the variable names
attr(mf, "text") # Corresponding text information as attribute
mf$ContentsCode # Data frame for the fifth variable (alternatively mf[[5]])
attr(mf,"elimination") # Finding variables that can be eliminated
ApiData(urlSCB, # Eliminating all variables that can be eliminated (line below)
Region = FALSE, Civilstand = FALSE, Alder = FALSE, Kon = FALSE,
ContentsCode = "BE0101N1", # Selecting a single ContentsCode by text input
Tid = TRUE) # Choosing all possible values of Tid.
##### Using data from Statfi to illustrate use of input by variable labels (valueTexts)
urlStatfi <- "https://pxdata.stat.fi/PXWeb/api/v1/en/StatFin/kuol/statfin_kuol_pxt_12au.px"
ApiData(urlStatfi, returnMetaFrames = TRUE)$Tiedot
ApiData(urlStatfi, Alue = FALSE, Vuosi = TRUE, Tiedot = "Population") # same as Tiedot = 21
##### Wrappers PxData and pxwebData
# Exact same output as ApiData
PxData(4861, Region = "0301", ContentsCode = TRUE, Tid = c(1, -1))
# Data organized differently
pxwebData(4861, Region = "0301", ContentsCode = TRUE, Tid = c(1, -1))
# Large query. ApiData will not work.
if(FALSE){ # This query is "commented out"
z <- PxData("https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy",
Region = TRUE, Civilstand = TRUE, Alder = 1:10, Kon = FALSE,
ContentsCode = "BE0101N1", Tid = 1:10, verbosePrint = TRUE)
}
##### Small example where makeNAstatus is in use
ApiData("04469", Tid = "2020", ContentsCode = 1, Alder = TRUE, Region = "3011")
Run the code above in your browser using DataLab