{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_12

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

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

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

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

View Full Document
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
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

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

View Full Document
Debugging: Traceback traceback does exactly as it says and traces back the nested function calls that lead to the error. Example
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online