Package 'kosis'

Title: Korean Statistical Information Service (KOSIS)
Description: API wrapper to download statistical information from the Korean Statistical Information Service (KOSIS) <https://kosis.kr/openapi/index/index.jsp>.
Authors: Seokhoon Joo [aut, cre]
Maintainer: Seokhoon Joo <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1
Built: 2024-11-20 05:35:37 UTC
Source: https://github.com/seokhoonj/kosis

Help Index


kosis: Korean Statistical Information Service (KOSIS)

Description

API wrapper to download statistical information from the Korean Statistical Information Service (KOSIS) https://kosis.kr/openapi/index/index.jsp.

Details

To use this package, you will first need to get your API key from the website https://kosis.kr/openapi/index/index.jsp. Once you have your key, you can save it as an environment variable for the current session using the kosis.setKey function. Alternatively, you can set it permanently by adding the following line to your .Renviron file:

KOSIS_API_KEY = PASTE YOUR API KEY

Any functions that require your API key try to retrieve it via Sys.getenv("KOSIS_API_KEY") (unless API key is explicitly specified as a function argument).

Author(s)

Maintainer: Seokhoon Joo [email protected]


Cast Item variable from the stat data downloaded from getStatData function

Description

Cast Item variable from the stat data downloaded from getStatData function

Usage

castItem(statData, itemVar = c("ITM_NM", "ITM_ID", "ITM_NM_ENG"))

Arguments

statData

A data.frame downloaded from getStatData function

itemVar

A string specifying item variable

Details

## Example
statData <- getStatData(orgId = "101", tblId = "DT_1B41", objL1 = "ALL")
castItem(statData = statData, itemVar = "ITM_NM")

Value

A data.frame object containing queried information


KOSIS Statistic Data

Description

KOSIS Statistic Data

Usage

getStatData(
  orgId,
  tblId,
  prdSe = c("Y", "H", "Q", "M", "D", "IR"),
  startPrdDe,
  endPrdDe,
  newEstPrdCnt = 3,
  prdInterval = 1,
  itmId = "ALL",
  objL1 = "ALL",
  objL2 = "",
  objL3 = "",
  objL4 = "",
  ...
)

Arguments

orgId

A string specifying the organization id

tblId

A string specifying the table id

prdSe

A string specifying the period symbol (Y, H, Q, M, D, IR: Irregularly)

startPrdDe

A string specifying start period (format: YYYY, YYYYMM(MM:01~12), YYYYHH(HH:01,02), YYYYQQ(QQ:01~04), YYYYMMDD)

endPrdDe

A string specifying end period (format: YYYY, YYYYMM(MM:01~12), YYYYHH(HH:01,02), YYYYQQ(QQ:01~04), YYYYMMDD)

newEstPrdCnt

A string specifying newest period count

prdInterval

A string specifying period interval

itmId

A string item id

objL1

A string specifying object level 1

objL2

A string specifying object level 2

objL3

A string specifying object level 3

objL4

A string specifying object level 4

...

A string specifying object level 5, 6, 7, 8 (objL5, objL6, objL7, objL8)

Details

## Example
getStatData(orgId = "101", tblId = "DT_1B41")

Value

A data.frame object containing queried information


KOSIS Statistic Data from URL

Description

KOSIS Statistic Data from URL

Usage

getStatDataFromURL(url)

Arguments

url

A string specifying the KOSIS URL

Details

## Example
url <- "https://kosis.kr/openapi/Param/statisticsParameterData.do?
method=getList&apiKey=&
itmId=T6+T16+T26+T5+T15+T25+T2+T12+T22+T3+T13+T23+T4+T14+T24+T1+T11+T21+&
objL1=ALL&objL2=&objL3=&objL4=&objL5=&objL6=&objL7=&objL8=&
format=json&jsonVD=Y&
prdSe=Y&newEstPrdCnt=3&prdInterval=1&
orgId=101&tblId=DT_1B41"
getStatDataFromURL(url = url)

Value

A data.frame object containing queried information


KOSIS Statistic Explanation

Description

KOSIS Statistic Explanation

Usage

getStatExpl(orgId, tblId, statId, metaItm = "ALL")

Arguments

orgId

A string specifying the organization id

tblId

A string specifying the table id

statId

A string specifying the stat id

metaItm

A string specifying the meta item

Details

## Example
getStatExpl(orgId = "101", tblId = "DT_1L9V054")
getStatExpl(statId = "1962009")

Value

A data.frame object containing queried information


KOSIS Statistic List

Description

KOSIS Statistic List

Usage

getStatList(
  vwCd = c("MT_ZTITLE", "MT_OTITLE", "MT_GTITLE01", "MT_GTITLE02", "MT_CHOSUN_TITLE",
    "MT_HANKUK_TITLE", "MT_STOP_TITLE", "MT_RTITLE", "MT_BUKHAN", "MT_TM1_TITLE",
    "MT_TM2_TITLE", "MT_ETITLE"),
  parentListId = ""
)

Arguments

vwCd

A string specifying the view code

parentListId

A string specifying the parent list id

Details

## Example
getStatList(vwCd = "MT_ZTITLE", parentListId = "")
getStatList(vwCd = "MT_ZTITLE", parentListId = "F")
getStatList(vwCd = "MT_ZTITLE", parentListId = "F_29")

Value

A data.frame object containing queried information


KOSIS Statistic Meta

Description

KOSIS Statistic Meta

Usage

getStatMeta(
  orgId,
  tblId,
  type = c("TBL", "ORG", "PRD", "ITM", "CMMT", "UNIT", "SOURCE", "WGT", "NCD")
)

Arguments

orgId

A string specifying the organization id

tblId

A string specifying the table id

type

A string specifying the meta type

Details

## Example
getStatMeta(orgId = "101", tblId = "DT_1IN0001")
getStatMeta(orgId = "101", tblId = "DT_1IN0001", type = "ORG")

Value

A data.frame object containing queried information


KOSIS Statistic Search

Description

KOSIS Statistic Search

Usage

getStatSearch(
  searchNm,
  startCount = 1,
  resultCount = 20,
  sort = c("RANK", "DATE")
)

Arguments

searchNm

A string specifying a name you search

startCount

A nuemeric specifying a page number

resultCount

A numeric specifying counts of result (resultCount = 20, startCount = 2 : 21~40 Result)

sort

A string specifying the sorting (RANK: accuracy, DATE: newest)

Details

## Example
getStatSearch(searchNm = "CPI")

Value

A data.frame object containing queried information


Set KOSIS API Key

Description

Save KOSIS API key for the current session. To set it permanently, please add the following line to your .Renvrion file:

KOSIS_API_KEY = "YOUR API KEY"

Usage

kosis.setKey(apiKey)

kosis.printKey()

Arguments

apiKey

A string specifying KOSIS API key

Value

No return value, called to set api key

Examples

## Set API Key for the current session
kosis.setKey("your_api_key")

## Check API key
kosis.printKey()

Remove columns that consist of unique values

Description

Remove columns that consist of unique values

Usage

removeUniqueCols(statData)

Arguments

statData

A data.frame downloaded from getStatData function

Details

## Example
df <- removeUniqueCols(statData = statData)

Value

A data.frame object with columns that consist of non-unique values