lecture_12

lecture_12 - BIOS 735: Statistical Computing Michael Wu...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
BIOS 735: Statistical Computing Michael Wu Lecture 12: Debugging and Timing October 4, 2011 Michael Wu (Lecture 12) BIOS 735 October 4, 2011 1 / 12
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Debugging (Almost) nobody is perfect: your code will have errors. Sometimes your code dies or R tells you that something is wrong: I Warning I Error Sometimes your code doesn’t give you the results you expected. I Is the method I’ve proposed for my dissertation wrong? I Is it my code that’s wrong? I Most of the time it’s your code (*phew*). There are many different ways to help search for the errors in your code, i.e. debugging Example Something is wrong: myLog = function(x, base) { log(x)/log(base) } myLog(c(2,4,10,8,16), 2) myLog(-1:10,3) myLog("foot",12) Michael Wu (Lecture 12) BIOS 735 October 4, 2011 2 / 12
Background image of page 2
Debugging: Using print and cat statements To monitor variable values and see what’s going on, you can ask your program to periodically spit out output. This is very versatile and can be used across languages. Considered blasphemy by the R programming community. myLog = function(x, base) { out = rep(NA, length(x)) for (i in seq(length(x))){ print(x[i]) cat(log(x[i]), log(base),"\n") out[i] =log(x[i])/log(base) } return(out) } myLog(c(2,4,10,8,16), 2) myLog(-1:10,3) myLog("foot",12) Michael Wu (Lecture 12) BIOS 735 October 4, 2011 3 / 12
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Debugging: Traceback traceback does exactly as it says and traces back the nested function calls that lead to the error. Example
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/18/2011 for the course BIOS 735 taught by Professor Staff during the Spring '10 term at UNC.

Page1 / 12

lecture_12 - BIOS 735: Statistical Computing Michael Wu...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online