Learn R Programming

Rnightlights (version 0.1.2)

getCtryNlData: Returns nightlight statistics for the given ctryCode and nlType in the given nPeriods

Description

Returns nightlight data for the given ctryCode and stats in the given nlPeriods and of the specified nlType. Note that getCtryNldata only processes one ctryCode at a time. ignoreMissing plays a significant role here. It can take 3 values:

  • NULL (default) only return data if found for all nlPeriods and all stats provided otherwise return NULL.

  • TRUE return any partial data that is found for the provided nlPeriods and stats. Ignore any missing data.

  • FALSE return all data that is found and call processNlData to download and process any missing nlPeriods and stats.

Farther, if nlPeriods is missing, it is assigned values based on the value of ignoreMissing. If ignoreMissing is FALSE, nlPeriods is assigned all existing nlPeriods to date. This is the equivalent of retrieving all nightlight data for the given country and stats. If ignoreMissing is TRUE or NULL then the existing data is returned.

Usage

getCtryNlData(ctryCode, nlPeriods, nlType, stats = pkgOptions("stats"),
  ignoreMissing = NULL, source = "local")

Arguments

ctryCode

the ISO3 code of the country. Only 1 country can be processed at a time

nlPeriods

a vector of nlPeriods. Must be appropriate nlPeriods for the nlType.

nlType

the nightlight type i.e. "OLS" or "VIIRS" (default)

stats

a vector of stats. if not supplied defaults to all stats as listed in pkgOptions("stats")

ignoreMissing

controls how the function behaves if any data is not found in the data file

  • NULL (default) only return data if found for ALL nlPeriods and ALL stats provided otherwise return NULL

  • TRUE return any partial data that is found for the provided nlPeriods and stats. Ignore any missing data

  • FALSE return all data that is found and call processNlData to download and process any missing nlPeriods and stats

source

"local" or "remote" Whether to download and process the data locally or to download the pre-processed data from a remote source/repo

Value

dataframe of data for one country in one nlType in one or multiple nlPeriods

Examples

Run this code
# NOT RUN {
#missing stats implies all stats as given by pkgOptions("stats")

# }
# NOT RUN {
getCtryNlData("KEN", nlType="VIIRS", ignoreMissing=NULL)
# }
# NOT RUN {
    #returns all existing data i.e. all nlPeriods and all stats for KEN

# }
# NOT RUN {
getCtryNlData("KEN", ignoreMissing=TRUE)
# }
# NOT RUN {
    #same as ignoreMissing=NULL. Returns all existing data i.e. all nlPeriods
    #and all stats for KEN
 
# }
# NOT RUN {
getCtryNlData(ctryCode="KEN", nlType="VIIRS", ignoreMissing=FALSE)
# }
# NOT RUN {
    #for any missing data between 201204 to present download and process the
    #data then return all data
 
# }
# NOT RUN {
getCtryNlData("KEN", nlPeriod=c("existingNlPeriod", "missingNlPeriod"),
    stats=c("sum", "unknownStat"), ignoreMissing=NULL)
# }
# NOT RUN {
    #Returns NULL
    #(ignoreMissing=NULL returns all data if exists or if any is missing returns NULL)

# }
# NOT RUN {
getCtryNlData("KEN", nlPeriods=c("existingNlPeriod", "missingNlPeriod"),
    stats=c("existingStat", "missingStat"), ignoreMissing=TRUE)
# }
# NOT RUN {
   #Returns existingStat for existingNlPeriods
   #(ignoreMissing=TRUE returns only existing data)
 
# }
# NOT RUN {
getCtryNlData("KEN", nlYearPeriods=c("existingNlPeriod", "missingNlPeriod"),
    stats=c("sum", "unknownStat"), ignoreMissing=FALSE)
# }
# NOT RUN {
    #Runs processNlData for missingStat in "missingNlPeriod" and returns
    #"existingStat" and "missingStat" for both "existingNlPeriod" and
    #"missingNlPeriod"
    #(ignoreMissing=FALSE must return all data: forces processing of any missing)
 
# }

Run the code above in your browser using DataLab