Hi All,
I am having trying to cat different strings to a file for different conditions using if - else statements:
cat("<graph caption=\"ECG Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" showValues=\"0\" showAlternateHGridColor=\"1\" AlternateHGridColor=\"ff5904\" divLineColor=\"ff5904\" divLineAlpha=\"20\" alternateHGridAlpha=\"5\">\n")
if (df$BP > 140 && df$Yvoltage < -0.05){
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity Low\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))else
if (df$BP > 140 && df$Yvoltage > -0.05)
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure Normal, Level of Activity Normal\" ></set>\n", df$XTimeStamp, df$YVoltage, diff)) else
if (df$BP > 140 && df$Yvoltage > -0.35)
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity High\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))}
cat(' <trendlines>
<line startvalue="0.30" displayValue="High Activity" color="FF0000" thickness="1" isTrendZone="0"></line>
<line startvalue="-0.05" displayValue="Low Activity" color="009999" thickness="1" isTrendZone="0"></line>
\n') cat ("\n")
When I try to run the code I keep getting an error as follows:
Error: unexpected 'else' in:
"if (df$BP > 140 && df$Yvoltage < -0.05){
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = \"Blood Pressure High, Level of Activity Low\" ></set>\n", df$XTimeStamp, df$YVoltage, diff))else"
Any ideas where I am going wrong? Is this the right way do this are is there a better way to write the file?
I am trying to follow Spacedman's advice and use brew. I have tried different variances of it and I either get the following error message:
Error: unexpected input in "cat (sprintf(" <set name=\"%s\" value=\"%f\" hoverText = "<%= hovertext =>" ></set>\n", df$XTimeStamp, df$YVoltage))"
or if I get it working the hovertext remains the same the whole way down.
Currently the R code is as follows:
if(df$BP > 140 && df$YVoltage < -0.05){
hovertext ="Blood Pressure High, Level of Activity Low"
}else{
if(df$BP < 140 && df$BP > 90 && df$YVoltage > -0.05 && df$YVoltage < 0.30 ){
hovertext ="Blood Pressure normal, Level of Activity normal"
} else {
hovertext ="Blood Pressure High, Level of Activity high"
}
sink (file="c:/Users/usr/Desktop/data.xml", type="output",split=FALSE)
cat("<graph caption=\"ECG Data Wave\" subcaption=\"For Person's Name\" xAxisName=\"Time\" yAxisMinValue=\"-0.025\" yAxisName=\"Voltage\" decimalPrecision=\"5\" formatNumberScale=\"0\" numberPrefix=\"\" showNames=\"1\" showValues=\"0\" showAlternateHGridColor=\"1\" AlternateHGridColor=\"ff5904\" divLineColor=\"ff5904\" divLineAlpha=\"20\" alternateHGridAlpha=\"5\">\n")
cat(sprintf(" <set name=\"%s\" value=\"%f\" hoverText = "<%= hovertext =>" ></set>\n", df$XTimeStamp, df$YVoltage))
cat(' <trendlines>
<line startvalue="0.30" displayValue="High Activity" color="FF0000" thickness="1" isTrendZone="0"></line>
<line startvalue="-0.05" displayValue="Low Activity" color="009999" thickness="1" isTrendZone="0"></line>
</trendlines>\n')
cat ("</graph>\n")
unlink("data.xml")
Any ideas on where I am still going wrong in the code?