Title: | R Interface for China National Data |
---|---|
Description: | R interface for china national data <http://data.stats.gov.cn/>, some convenient functions for accessing the national data are provided. |
Authors: | Xuehui YANG |
Maintainer: | Xuehui YANG <[email protected]> |
License: | Apache License 2.0 |
Version: | 1.1.3 |
Built: | 2025-03-10 05:04:45 UTC |
Source: | https://github.com/jiang-hang/rstatscn |
private function for check the http status
checkHttpStatus(ret)
checkHttpStatus(ret)
ret |
the response obj returned by httr package |
return nothing , but if it finds some error , it stop the script
private function to convert the returned jason data to a dataframe
dataJson2df(rawObj, rowcode, colcode)
dataJson2df(rawObj, rowcode, colcode)
rawObj |
the fromJSON output |
rowcode |
rowcode in the data frame |
colcode |
colcode in the data frame |
the contructed data frame
private function for constructing the query parameter for dfwds
genDfwds(wdcode, valuecode)
genDfwds(wdcode, valuecode)
wdcode |
string value , one of c("zb","sj","reg") |
valuecode |
string value , following is the table for available valuecode zb: the valudecode can be gotten by statscnQueryZb() function sj: the valudecode can be "2014" for nd db, "2014C" for jd db. reg: the valudecode is the region code fetched by statscnRegions(dbcode) function |
return the queyr string for the http request
the available dbs in the national db
statscnDbs()
statscnDbs()
a data frame with 2 columns , one is the dbcode, another is the db description
statscnDbs()
statscnDbs()
the main function for querying the statscn database, it will retrieve the data from specified db and orginize the data in a data frame.
statscnQueryData(zb = "A0201", dbcode = "hgnd", rowcode = "zb", colcode = "sj", moreWd = list(name = NA, value = NA))
statscnQueryData(zb = "A0201", dbcode = "hgnd", rowcode = "zb", colcode = "sj", moreWd = list(name = NA, value = NA))
zb |
the zb/category code to be queried |
dbcode |
the db code for querying |
rowcode |
rowcode in the returned data frame |
colcode |
colcode in the returned data frame |
moreWd |
more constraint on the data where the name should be one of c("reg","sj") , which stand for region and sj/time. the valuecode for reg should be the region code queried by statscnRegions() the valuecode for sj should be like '2014' for *nd , '2014C' for *jd , '201405' for *yd. Be noted that , the moreWd name should be different with either rowcode or colcode |
the data frame you are quering
## Not run: df=statscnQueryData('A0201',dbcode='hgnd') df=statscnQueryData('A0201',dbcode='fsnd',rowcode='zb',colcode='sj', moreWd=list(name='reg',value='110000')) ## End(Not run)
## Not run: df=statscnQueryData('A0201',dbcode='hgnd') df=statscnQueryData('A0201',dbcode='fsnd',rowcode='zb',colcode='sj', moreWd=list(name='reg',value='110000')) ## End(Not run)
fetch the lastN data for the latest query, only affect the number of rows in the returned data. This function can not be used alone , statscnQueryData() has to be called before this function
statscnQueryLastN(n)
statscnQueryLastN(n)
n |
the number of rows to be fetched |
the last n rows data in the latest query
## Not run: df=statscnQueryData('A0201',dbcode='hgnd') df2=statscnQueryLastN(20) ## End(Not run)
## Not run: df=statscnQueryData('A0201',dbcode='hgnd') df2=statscnQueryLastN(20) ## End(Not run)
the sub data categories for the zbid category, dbcode need to be specified, where the dbcode can be fetched by function statscnDbs(). In the returned data frame, the column 'isParent' shows if each sub category is leap category or not
statscnQueryZb(zbid = "zb", dbcode = "hgnd")
statscnQueryZb(zbid = "zb", dbcode = "hgnd")
zbid |
the father zb/category id , the root id is 'zb' |
dbcode |
which db will be queried |
the data frame with the sub zbs/categories , if the given zbid is not a Parent zb/category, null list is returned
## Not run: statscnQueryZb() statscnQueryZb('A01',dbcode="hgnd") ## End(Not run)
## Not run: statscnQueryZb() statscnQueryZb('A01',dbcode="hgnd") ## End(Not run)
the available regions in the specified db, it is used for query the province, city and country code generally
statscnRegions(dbcode = "fsnd")
statscnRegions(dbcode = "fsnd")
dbcode |
the dbcode should be some province db(fs*) , city db(cs*) or internaltional db(gj*) |
the data frame with all the available region codes and names in the db
## Not run: statscnRegions('fsnd') statscnRegions('csnd') statscnRegions('gjnd') ## End(Not run)
## Not run: statscnRegions('fsnd') statscnRegions('csnd') statscnRegions('gjnd') ## End(Not run)
set the rowName prefix in the dataframe
statscnRowNamePrefix(p = "nrow")
statscnRowNamePrefix(p = "nrow")
p |
, how to set the rowname prefix. it is 'nrow' by default , and it is the only supported value currently to unset the row name prefix, call this function with p=NULL |
in case you encounter the following error: Error in 'row.names<-.data.frame'('*tmp*', value = value) : duplicate 'row.names' are not allowed you need to call this function
no return