0% found this document useful (0 votes)
10 views10 pages

Exception

The document discusses error handling in R, explaining the difference between errors and warnings, and how to catch errors using try statements. It also covers tracking progress and timing for lengthy computations, including the use of progress bars and the Sys.time command. Additionally, it addresses issues with object name clashes in packages and how to unmount packages using the detach function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views10 pages

Exception

The document discusses error handling in R, explaining the difference between errors and warnings, and how to catch errors using try statements. It also covers tracking progress and timing for lengthy computations, including the use of progress bars and the Sys.time command. Additionally, it addresses issues with object name clashes in packages and how to unmount packages using the detach function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exception

Exception
• When there’s an unexpected problem during execution of a function,
R will notify you with either a warning or an error
Errors and Warnings
• An error forces the function to immediately terminate at the point it
occurs
• A warning is less severe. It indicates that the function is being run in
an atypical way but tries to work around the issue and continue
executing
• Warnings can be issued using warning command
• throw errors using stop command
Catching errors
• when a function terminates from an error, it also terminates any
parent functions.
• For example:
If function A calls function B and function B halts because of an error,
this halts execution of A at the same points. To avoid this severe
consequences, you can use try statement to attempt a function call and
check whether it produces an error. You can also use if statement to
specify alternative operations, rather than allowing all processes to
cease
Progress and Timing
• R is often used for lengthy numeric exercises, such as simulation or
random variate generation. For these complex, time-consuming
operations, it’s often useful to keep track progress or see how long a
certain task took to complete
textual Progess Bars
• A progress bar shows how far along R is as it executes a set of
operations.
• To show how this works, you need to run code that takes a while to
execute, which you’ll do by making R sleep.
• The Sys.sleep command makes R pause for a specified amount of
time, in seconds before continuing
Measuring Completion Time
• If you want to know how long a computation takes to complete, you
can use the Sys.time command.
• This command outputs an object that details current date and time
information based on your system
Masking
• With the plethora of built-in contributed data and functionality
available for R, it is virtually inevitable that at same point that you will
come across objects, usually functions, that share the same name in
distinctly different loaded packages
• Eg: if you define a function with the same name as a function in an
package that you have already loaded. R responds by masking one of
the objects
Package objects clash
• when you load a package, R will notify you if any of the objects in the
package clash with other objects that are accessible in the present
session.
Unmounting Packages
• You can unmount loaded packages from the search path.
• Suppose you don’t need any package, you can remove it with detach
function

You might also like