summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-10-09 22:54:45 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-09 23:18:53 +0200
commit5b095ed6f38bd54aa9d49403232bffa9918f82c1 (patch)
treec826ca00f1e19df05dc00fd668f9efa38f3c2c25 /tests
parente7a3f34959f9c20344c44469581488784d3153b3 (diff)
Fix line endings
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/R/test.r292
1 files changed, 146 insertions, 146 deletions
diff --git a/tests/syntax-tests/highlighted/R/test.r b/tests/syntax-tests/highlighted/R/test.r
index 16209b47..2196edef 100644
--- a/tests/syntax-tests/highlighted/R/test.r
+++ b/tests/syntax-tests/highlighted/R/test.r
@@ -1,170 +1,170 @@
# take input from the user
-num = as.integer(readline(prompt="Enter a number: "))
-factorial = 1
+num = as.integer(readline(prompt="Enter a number: "))
+factorial = 1
# check is the number is negative, positive or zero
-if(num < 0) {
-print("Sorry, factorial does not exist for negative numbers")
-} else if(num == 0) {
-print("The factorial of 0 is 1")
-} else {
-for(i in 1:num) {
+if(num < 0) {
+print("Sorry, factorial does not exist for negative numbers")
+} else if(num == 0) {
+print("The factorial of 0 is 1")
+} else {
+for(i in 1:num) {
factorial = factorial * i
-}
-print(paste("The factorial of", num ,"is",factorial))
-}
-
-x <- 0
-if (x < 0) {
-print("Negative number")
-} else if (x > 0) {
-print("Positive number")
-} else
-print("Zero")
-
-x <- 1:5
-for (val in x) {
-if (val == 3){
-next
-}
-print(val)
-}
-
-x <- 1
-repeat {
-print(x)
-x = x+1
-if (x == 6){
-break
-}
-}
-
-`%divisible%` <- function(x,y)
-{
-if (x%%y ==0) return (TRUE)
-else return (FALSE)
-}
-
-switch("length", "color" = "red", "shape" = "square", "length" = 5)
-[1] 5
-
-recursive.factorial <- function(x) {
-if (x == 0) return (1)
-else return (x * recursive.factorial(x-1))
-}
-
-pow <- function(x, y) {
+}
+print(paste("The factorial of", num ,"is",factorial))
+}
+
+x <- 0
+if (x < 0) {
+print("Negative number")
+} else if (x > 0) {
+print("Positive number")
+} else
+print("Zero")
+
+x <- 1:5
+for (val in x) {
+if (val == 3){
+next
+}
+print(val)
+}
+
+x <- 1
+repeat {
+print(x)
+x = x+1
+if (x == 6){
+break
+}
+}
+
+`%divisible%` <- function(x,y)
+{
+if (x%%y ==0) return (TRUE)
+else return (FALSE)
+}
+
+switch("length", "color" = "red", "shape" = "square", "length" = 5)
+[1] 5
+
+recursive.factorial <- function(x) {
+if (x == 0) return (1)
+else return (x * recursive.factorial(x-1))
+}
+
+pow <- function(x, y) {
# function to print x raised to the power y
result <- x^y
-print(paste(x,"raised to the power", y, "is", result))
-}
-
-A <- read.table("x.data", sep=",",
- col.names=c("year", "my1", "my2"))
+print(paste(x,"raised to the power", y, "is", result))
+}
+
+A <- read.table("x.data", sep=",",
+ col.names=c("year", "my1", "my2"))
nrow(A) # Count the rows in A
-
+
summary(A$year) 
-
+
A$newcol <- A$my1 + A$my2 # Makes a new
newvar <- A$my1 - A$my2 # Makes a 
A$my1 <- NULL # Removes 
-str(A)
-summary(A)
+str(A)
+summary(A)
library(Hmisc) 
-contents(A)
-describe(A)
-
+contents(A)
+describe(A)
+
set.seed(102) # This yields a good illustration.
-x <- sample(1:3, 15, replace=TRUE)
-education <- factor(x, labels=c("None", "School", "College"))
-x <- sample(1:2, 15, replace=TRUE)
-gender <- factor(x, labels=c("Male", "Female"))
-age <- runif(15, min=20,max=60)
-
-D <- data.frame(age, gender, education)
-rm(x,age,gender,education)
-print(D)
-
+x <- sample(1:3, 15, replace=TRUE)
+education <- factor(x, labels=c("None", "School", "College"))
+x <- sample(1:2, 15, replace=TRUE)
+gender <- factor(x, labels=c("Male", "Female"))
+age <- runif(15, min=20,max=60)
+
+D <- data.frame(age, gender, education)
+rm(x,age,gender,education)
+print(D)
+
# Table about education
-table(D$education)
-
+table(D$education)
+
# Table about education and gender --
-table(D$gender, D$education)
+table(D$gender, D$education)
# Joint distribution of education and gender --
-table(D$gender, D$education)/nrow(D)
-
+table(D$gender, D$education)/nrow(D)
+
# Add in the marginal distributions also
-addmargins(table(D$gender, D$education))
-addmargins(table(D$gender, D$education))/nrow(D)
-
+addmargins(table(D$gender, D$education))
+addmargins(table(D$gender, D$education))/nrow(D)
+
# Generate a good LaTeX table out of it --
-library(xtable)
-xtable(addmargins(table(D$gender, D$education))/nrow(D),
+library(xtable)
+xtable(addmargins(table(D$gender, D$education))/nrow(D),
 digits=c(0,2,2,2,2)) 
-
-by(D$age, D$gender, mean)
-by(D$age, D$gender, sd)
-by(D$age, D$gender, summary)
-
-a <- matrix(by(D$age, list(D$gender, D$education), mean), nrow=2)
-rownames(a) <- levels(D$gender)
-colnames(a) <- levels(D$education)
-print(a)
-print(xtable(a))
-
-dat <- read.csv(file = "files/dataset-2013-01.csv", header = TRUE)
-interim_object <- data.frame(rep(1:100, 10),
- rep(101:200, 10),
- rep(201:300, 10))
+
+by(D$age, D$gender, mean)
+by(D$age, D$gender, sd)
+by(D$age, D$gender, summary)
+
+a <- matrix(by(D$age, list(D$gender, D$education), mean), nrow=2)
+rownames(a) <- levels(D$gender)
+colnames(a) <- levels(D$education)
+print(a)
+print(xtable(a))
+
+dat <- read.csv(file = "files/dataset-2013-01.csv", header = TRUE)
+interim_object <- data.frame(rep(1:100, 10),
+ rep(101:200, 10),
+ rep(201:300, 10))
object.size(interim_object) 
rm("interim_object") 
ls() 
-rm(list = ls())
-
-vector1 <- c(5,9,3)
-vector2 <- c(10,11,12,13,14,15)
-array1 <- array(c(vector1,vector2),dim = c(3,3,2))
-vector3 <- c(9,1,0)
-vector4 <- c(6,0,11,3,14,1,2,6,9)
-array2 <- array(c(vector1,vector2),dim = c(3,3,2))
-matrix1 <- array1[,,2]
-matrix2 <- array2[,,2]
+rm(list = ls())
+
+vector1 <- c(5,9,3)
+vector2 <- c(10,11,12,13,14,15)
+array1 <- array(c(vector1,vector2),dim = c(3,3,2))
+vector3 <- c(9,1,0)
+vector4 <- c(6,0,11,3,14,1,2,6,9)
+array2 <- array(c(vector1,vector2),dim = c(3,3,2))
+[38;2;248;248;242