-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_csv2rda.sh
executable file
·59 lines (47 loc) · 1.62 KB
/
2_csv2rda.sh
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
#!/bin/bash
projecthome=~/UdallR
while getopts ":f" opt ; do
case ${opt} in
f)
echo "Will overwrite multivis"
shift 1
FORCE=yes ;;
\?)
echo "Invalid option: -${OPTARG}" ;;
esac
done
newdate=${1}
if [[ ${FORCE} == "yes" ]] ; then
rm -f ${projecthome}/data/panuc_multivis_20${newdate}.rda
fi
# Check input for correct format
if [[ ! ${newdate} =~ ^([0-9]{2}_){2}[0-9]{2}$ ]] ; then
echo "Error: Invalid date format: ${newdate}"
echo "Expecting: YY_MM_DD"
exit 1
fi
if [[ ! -e ${projecthome}/data/panuc_multivis_20${newdate}.csv ]] ; then
# Check that the csv needed exists; exit if it doesn't.
echo "Error: ${projecthome}/data/panuc_multivis_20${newdate}.csv" \
"does not exist"
exit 1
else
if [[ -e ${projecthome}/data/panuc_multivis_20${newdate}.rda ]] ; then
# Don't run the code if the output rda file aready exists.
echo "${projecthome}/data/panuc_multivis_20${newdate}.rda" \
"already exists."
echo "Run ${projecthome}/update-multivis ${newdate} to update."
else
# Use R to convert csv to rda
R --no-save --slave <<-EOF
panuc_multivis_20${newdate} <- \
read.csv("data/panuc_multivis_20${newdate}.csv")
cat("Loaded:", dim(panuc_multivis_20${newdate}), fill = TRUE)
save(panuc_multivis_20${newdate}, \
file = "data/panuc_multivis_20${newdate}.rda")
EOF
# The next step is to update the relevant files.
echo "Now run:"
echo "${projecthome}/3_update-multivis.sh ${newdate}"
fi
fi