#	R code with examples for loading data into apc

##################################################
#	getting started
##################################################
#	attach apc library
library(apc)
#	set directory where files are store
#   ex: drive <- "c:/datadirectory/"
drive <- ""

##################################################
#	csv
##################################################
#	use read.csv from utils package
#	plus:	1) included in default R installation
#			2) recognises a first column with row labels
#	minus:	cannot read sheets in csv from excel
#
#	read csv files
data.1.response <- read.csv(paste(drive,"data_Belgian_lung_cancer_response.csv",sep=""),check.names=F,row.names=1)
data.1.rates    <- read.csv(paste(drive,"data_Belgian_lung_cancer_rates.csv"   ,sep=""),check.names=F,row.names=1)
#   these objects are in data.frame format
#   so need to be converted to matrix
m.1.response    <- as.matrix(data.1.response)
m.1.rates       <- as.matrix(data.1.rates)
#   convert to apc.data.list format
data.1   <- apc.data.list(m.1.response,"AP",m.1.response/m.1.rates, age1=25,per1=1955,unit=5,label="Belgian lung cancer")

##################################################
#	xlsx
##################################################
#	use read_excel from readxl package
#	plus:	no dependencies on other packages
#	minus:	does not recognise a first column with row labels
#
#   get library
library(readxl)
#   read xlsx file
data.2.response <- read_excel(paste(drive,"data_Belgian_lung_cancer.xlsx",sep=""), sheet=1)      
data.2.rates    <- read_excel(paste(drive,"data_Belgian_lung_cancer.xlsx",sep=""), sheet=2)      
#   these objects are in data.frame format
#   so need to be converted to matrix
#   & first column has row labels. 
m.2.response  <- as.matrix(data.2.response[,2:5])
m.2.rates     <- as.matrix(data.2.rates[,2:5])
row.names(m.2.response) <- data.2.response[,1]
row.names(m.2.rates)    <- data.2.rates[,1]
#   convert to apc.data.list format
data.2. <- apc.data.list(m.2.response,"AP",m.2.response/m.2.rates, age1=25,per1=1955,unit=5,label="Belgian lung cancer")
