### This file describes a script for testing the connection. ### $Revision: 1.1.1.1 $ ### $Date: 2005/01/06 14:58:12 $ ###Parameters: asp.user <- "ralmond" asp.dbname <- "ICT_exp1" ### Set things up library("RMySQL") ### Note: On windows, might need to ## source("C:/Program Files/R/rw1091/library/RMySQL/R/RMySQL.R") asp.driver <- MySQL() if(.Platform$OS.type == "unix") { StatShop <- system("echo $STATSHOP", intern=TRUE) } else if(.Platform$OS.type == "windows") { StatShop <- system(paste(Sys.getenv("COMSPEC"),"/c","echo %STATSHOP%"), intern=TRUE) } source(paste(StatShop,"R","Asp","access.q",sep=.Platform$file.sep)) ###Connect to database asp.dbConnect() asp.repairAllTables <- ### This function runs repair tables on all tables in a database. ### It should do no harm. function () { tables <- dbListTables(asp.con) for (table in tables) { rquery <- paste("REPAIR TABLE ",table,";") print(dbGetQuery(asp.con,rquery)) } } asp.repairAllTables() asp.trimTables <- ### This function deletes all records for cycles greater than cycle in ### in chain. Recommended best practice is to delete the last two ### cycles if an MCMC run crashes in the middle. asp.getCycles() ### can help you determine where the calibrator was during the crash. ### WARNING: This function will destructively modify the database. function (cycle, chain) { models <- asp.listModels() fixTable <- function (table,cycle,chain) { fquery <- paste("DELETE FROM ",table, " WHERE CYCLE >= ",cycle, " AND CHAIN = ",chain,";") print(fquery) dbGetQuery(asp.con,fquery) } for (model in models) { fixTable(asp.parameterTable(model),cycle,chain) fixTable(asp.variableTable(model),cycle,chain) } ## Now fix chain_data_table; cquery <- paste("UPDATE chain_data_table", " SET chain_last_cycle =",cycle-1, " WHERE CHAIN =",chain,";") print(cquery) dbGetQuery(asp.con,cquery) } ###Check status of chains asp.getCycles() ### You will want to run this next part manually. ### Adjust the chain a couple of cycles back to be sure all is ### cleanly written. For example, if # > asp.getCycles() # chain_first_cycle chain_last_cycle # 1 1 3000 # 2 1 1270 # 3 1 -1 ## Then you might use: ##asp.trimTables(1268,chain=2) ## Again for sanity check. asp.getCycles()