Use Rmarkdown to demonstrate the skills below. Be brief and clear. Provide explanations if necessary to ensure clarity.

1. Run the program file (filename1.R) using the ‘source’ command;

Note - I’m not sure where to obtain filename1.R and couldn’t find directions in the syllabus/the project 1 description finding it. For this reason I just created my own filename1.r and filename2.r.

setwd("~/Desktop/repitest/")
source("filename1.R")
## [1] "Successfully source file1name"

2. Demonstrate reading an ASCII data file (filename2.dat) to create a ‘data frame’;

#df <- read.table("filename2.dat")

3. Demonstrate simple data manipulation (e.g., variable transformation, recoding, etc.);

x <- (1:10)
x[3:8] <- "changed"
x
##  [1] "1"       "2"       "changed" "changed" "changed" "changed" "changed"
##  [8] "changed" "9"       "10"

4. Demonstrate the use of calendar and Julian dates;

# convert date
date <- as.Date('April 26, 2001',format='%B %d, %Y')
# then get day of date
weekdays(date)
## [1] "Thursday"

5. Conduct a simple analysis using existing functions (from R, colleagues, etc.);

x <- 1:10
sumx <- sum(x)
library(testthat)
test_that("Correct mode", {

    sumx <- sum(x)

    expect_that( sumx, is_a("integer") )
})

6. Conduct a simple analysis demonstrating simple programming (e.g., a ‘for’ loop);

# Multiply even elements by 10
x <- (1:10)
for (i in seq_along(x)) {
  if (i%%2 == 0){
    x[i] <- i * 10
  }
}
x
##  [1]   1  20   3  40   5  60   7  80   9 100

7. Conduct a simple analysis demonstrating an original function created by student;;

who_is_the_coolest_professor <- function() {return("Tomas Aragon")}

8. Create a simple graph with title, axes labels and legend, and output to file;

df2 <- data.frame(x=1:10,y=sample(100,10))
png(filename="~/Desktop/repitest/imageforproject1.png")
plot(df2$x, df2$y, xlab="x values",ylab="y values", main="Simple plot", 'l', col='tomato', lwd=15)
dev.off()
## quartz_off_screen 
##                 2

9. Demonstrate the use of regular expressions;

grep("a+", c("abc", "def", "cba a", "aa"), perl=TRUE, value=TRUE)
## [1] "abc"   "cba a" "aa"

10. Demonstrate the use of the ‘sink’ function to generate an output file

#sink('~/Desktop/repitest/') # open connection
cat('Here are results of sumx function', fill = TRUE)
## Here are results of sumx function
show(sumx) 
## [1] 55
#sink() # close connection