-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunSummaries.R
111 lines (96 loc) · 2.84 KB
/
RunSummaries.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
##### Header #####
#
# Author: Matthew H. Grinnell
# Affiliation: Pacific Biological Station, Fisheries and Oceans Canada (DFO)
# Group: Quantitative Assessment Methods Section
# Address: 3190 Hammond Bay Road, Nanaimo, BC, Canada, V9T 6N7
# Contact: e-mail: [email protected] | tel: (250) 756.7055
# Project: Herring
# Code name: RunSummaries.R
# Version: 1.0
# Date started: Jun 16, 2017
# Date edited: Feb 12, 2018
#
# Overview:
# Run all the data summaries in turn.
#
# Requirements:
# The data summary script, 'Summary.R'.
#
# Notes:
# Comment-out the 'clear workspace' line in 'Summary.R'.
##### Housekeeping #####
# General options
rm(list = ls()) # Clear the workspace
sTimeAll <- Sys.time() # Start the timer
graphics.off() # Turn graphics off
# # Make packages available
# UsePackages( pkgs=c("foreach", "doSNOW") )
##### Controls #####
# Region names: major, minor, special, all
regionNames <- c("HG", "PRD", "CC", "SoG", "WCVI",
"A27", "A2W",
"A10",
"All")
# Initialize some cores
# clust <- makeCluster( 4 )
# registerDoSNOW( cluster )
##### Main #####
# Load helper functions
source(file = file.path("..", "HerringFunctions", "Functions.R"))
# Message re data summaries
cat(
"Summarising data for", length(regionNames), "regions:",
PasteNicely(regionNames), "\n\n"
)
# Loop over regions
for (r in 1:length(regionNames)) {
# Get list of objects to keep
lsKeep <- c("sTimeAll", "regionNames", "r")
# Remove everything else
rm(list = ls()[!ls() %in% lsKeep])
# Turn off graphics
graphics.off()
# Get the region
region <- regionNames[r]
# Run the data summary depending on the region
source(file = "Summary.R")
# Put a space
cat("\n")
} # End loop over regions
# Function to run the summary
RunSummary <- function(reg, ...) {
# # Get list of objects to keep
# lsKeep <- c( "sTimeAll", "regionNames", "r", "reg" )
# # Remove everything else
# rm( list=ls()[!ls() %in% lsKeep] )
# # Turn off graphics
# graphics.off( )
# Get the region
region <- reg
# Run the data summary depending on the region
source(file = "Summary.R")
return(1)
} # End RunSummary function
## Number of cores
# nCores <- detectCores( ) - 1
#
## Initiate the cluster
# clust <- makeCluster( nCores )
#
## Export variables to the cluster
# clusterExport( clust, varlist=c("regionNames") )
#
## Apply over regions
## clusterApply( cl=clust, x=regionNames, fun=RunSummary )
## parSapply( cl=clust, X=regionNames, FUN=RunSummary, reg=regionNames )
# parApply( cl=clust, X=array(regionNames), FUN=RunSummary, MARGIN=1, reg=regionNames )
#
## Close the cluster
# stopCluster( cl=clust )
##### End #####
# Stop the cluster
# stopCluster( clust )
# Print end of file message and elapsed time
cat("End of file RunSummaries.R: ", sep = "")
print(Sys.time() - sTimeAll)