2. Check R Version

print(paste("R Version:", R.version.string))
## [1] "R Version: R version 4.4.2 (2024-10-31 ucrt)"

3. Basic Math Operation

result <- 5 + 5
print(paste("5 + 5 =", result))
## [1] "5 + 5 = 10"

4. Install and Load a Package

Install ggplot2 if not already installed

if (!require(ggplot2)) {
  install.packages("ggplot2")
}
## Loading required package: ggplot2
library(ggplot2)
print("ggplot2 package loaded successfully.")
## [1] "ggplot2 package loaded successfully."

5. Create a Simple Data Frame

data <- data.frame(
  x = 1:10,
  y = (1:10)^2
)
print("Data Frame Created:")
## [1] "Data Frame Created:"
print(data)
##     x   y
## 1   1   1
## 2   2   4
## 3   3   9
## 4   4  16
## 5   5  25
## 6   6  36
## 7   7  49
## 8   8  64
## 9   9  81
## 10 10 100

6. Plot the Data

plot(data$x, data$y, type = "b", col = "blue", 
     main = "Basic Line Plot", xlab = "X Values", ylab = "Y Values")

# 7. Generate a ggplot

ggplot(data, aes(x = x, y = y)) +
  geom_line(color = "red") +
  geom_point(color = "blue") +
  ggtitle("ggplot Example") +
  xlab("X Values") +
  ylab("Y Values")

8. Save the ggplot to a File

ggsave(“test_plot.png”, width = 6, height = 4) print(“Plot saved as ‘test_plot.png’ in the current directory.”)

9. Check Working Directory

print(paste("Current Working Directory:", getwd()))
## [1] "Current Working Directory: C:/Users/OMPRAKASH/R Studio/Sample Program"

10. Session Info

print("Session Info:")
## [1] "Session Info:"
sessionInfo()
## R version 4.4.2 (2024-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=English_India.utf8  LC_CTYPE=English_India.utf8   
## [3] LC_MONETARY=English_India.utf8 LC_NUMERIC=C                  
## [5] LC_TIME=English_India.utf8    
## 
## time zone: Asia/Calcutta
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggplot2_3.5.1
## 
## loaded via a namespace (and not attached):
##  [1] vctrs_0.6.5       cli_3.6.3         knitr_1.49        rlang_1.1.4      
##  [5] xfun_0.50         jsonlite_1.8.9    labeling_0.4.3    glue_1.8.0       
##  [9] colorspace_2.1-1  htmltools_0.5.8.1 sass_0.4.9        scales_1.3.0     
## [13] rmarkdown_2.29    grid_4.4.2        evaluate_1.0.3    munsell_0.5.1    
## [17] jquerylib_0.1.4   tibble_3.2.1      fastmap_1.2.0     yaml_2.3.10      
## [21] lifecycle_1.0.4   compiler_4.4.2    pkgconfig_2.0.3   farver_2.1.2     
## [25] digest_0.6.37     R6_2.5.1          pillar_1.10.1     magrittr_2.0.3   
## [29] bslib_0.8.0       withr_3.0.2       tools_4.4.2       gtable_0.3.6     
## [33] cachem_1.1.0