Module V – Pointers in R
Programming
Packages, Frames, Debugging, Code
Manipulation, Compilation
1. Packages in R
• • A package is a collection of functions, data,
and documentation.
• • Structure: R/, data/, man/, DESCRIPTION,
NAMESPACE.
• • Commands:
• install.packages('ggplot2')
• library(ggplot2)
• • Creating a package: use devtools.
• • Popular packages: dplyr, ggplot2, caret,
2. Frames in R
• • Data frame: two-dimensional table-like
structure.
• • Each column can have different data types.
• • Example:
• df <- data.frame(Name=c('Ram','Sita'),
Age=c(25,28))
• • Access elements: df$Name, df[1,], df[,2]
• • Function environments create local frames.
3. Debugging in R
• • Common errors: syntax, logical, runtime.
• • Debugging tools:
• - traceback(): shows call stack
• - browser(): pauses execution
• - debug() / undebug(): step into/exit
• - recover(): inspect environment after error
• • Use print() or cat() for tracing.
4. Code Manipulation
• • Execute or modify R code dynamically.
• • Functions: eval(), parse(), quote(),
substitute().
• • Example:
• expr <- quote(x + y)
• eval(expr, list(x=10, y=5))
• • Profiling: Rprof(), summaryRprof().
5. Compilation in R
• • R supports byte-code compilation for speed.
• • Use compiler package:
• cmpfun(myfun)
• • JIT (Just-In-Time) compilation:
• enableJIT(3)
• • Interface with C/C++ using Rcpp.
Summary
• • Packages extend R functionalities.
• • Frames hold data or variable environments.
• • Debugging helps fix syntax and logical errors.
• • Code manipulation allows dynamic
execution.
• • Compilation improves performance.

Module_V_Pointers_R_Programming_VTU.pptx

  • 1.
    Module V –Pointers in R Programming Packages, Frames, Debugging, Code Manipulation, Compilation
  • 2.
    1. Packages inR • • A package is a collection of functions, data, and documentation. • • Structure: R/, data/, man/, DESCRIPTION, NAMESPACE. • • Commands: • install.packages('ggplot2') • library(ggplot2) • • Creating a package: use devtools. • • Popular packages: dplyr, ggplot2, caret,
  • 3.
    2. Frames inR • • Data frame: two-dimensional table-like structure. • • Each column can have different data types. • • Example: • df <- data.frame(Name=c('Ram','Sita'), Age=c(25,28)) • • Access elements: df$Name, df[1,], df[,2] • • Function environments create local frames.
  • 4.
    3. Debugging inR • • Common errors: syntax, logical, runtime. • • Debugging tools: • - traceback(): shows call stack • - browser(): pauses execution • - debug() / undebug(): step into/exit • - recover(): inspect environment after error • • Use print() or cat() for tracing.
  • 5.
    4. Code Manipulation •• Execute or modify R code dynamically. • • Functions: eval(), parse(), quote(), substitute(). • • Example: • expr <- quote(x + y) • eval(expr, list(x=10, y=5)) • • Profiling: Rprof(), summaryRprof().
  • 6.
    5. Compilation inR • • R supports byte-code compilation for speed. • • Use compiler package: • cmpfun(myfun) • • JIT (Just-In-Time) compilation: • enableJIT(3) • • Interface with C/C++ using Rcpp.
  • 7.
    Summary • • Packagesextend R functionalities. • • Frames hold data or variable environments. • • Debugging helps fix syntax and logical errors. • • Code manipulation allows dynamic execution. • • Compilation improves performance.