## ----error=TRUE--------------------------------------------------------------- f <- "C:\projects\research\data\obs.csv" ## ----------------------------------------------------------------------------- txt <- "Here is an example:\nA new line has started!\nAnd\tone\twith\ttabs\t...\t!\n" message(txt) ## ----------------------------------------------------------------------------- f1 <- "C:/projects/research/data/obs.csv" f2 <- "C:\\projects\\research\\data\\obs.csv" ## ----------------------------------------------------------------------------- file.exists(f1) ## ----------------------------------------------------------------------------- d <- data.frame(id=1:10, name=letters[1:10], value=seq(10,28,2)) d ## ----------------------------------------------------------------------------- write.csv(d, "test.csv", row.names=FALSE) write.table(d, "test.dat", row.names=FALSE) ## ----------------------------------------------------------------------------- file.exists("test.csv") file.exists("test.dat") ## ----------------------------------------------------------------------------- getwd() ## ----------------------------------------------------------------------------- file.path(getwd(), "test.csv") ## ----------------------------------------------------------------------------- d <- read.csv("test.csv", stringsAsFactors=FALSE) head(d) ## ----------------------------------------------------------------------------- d <- read.table("test.dat", stringsAsFactors=FALSE) head(d) ## ----------------------------------------------------------------------------- d <- read.table("test.dat", header=TRUE, stringsAsFactors=FALSE) head(d) ## ----------------------------------------------------------------------------- d <- read.table("test.dat", sep=",", stringsAsFactors=FALSE) ## ----------------------------------------------------------------------------- d <- readLines("test.csv") class(d) d ## ----------------------------------------------------------------------------- x <- sapply(d, function(i){ unlist(strsplit(i, ",")) }, USE.NAMES=FALSE) t(x) ## ----warning=FALSE------------------------------------------------------------ webpage <- readLines("https://rspatial.org/intr/6-files.html", warn=FALSE) #show some lines: webpage[293:295] ## ----------------------------------------------------------------------------- f <- readxl::readxl_example("datasets.xlsx") basename(f) ## ----------------------------------------------------------------------------- x <- readxl::read_excel(f) head(x) ## ----------------------------------------------------------------------------- x <- as.data.frame(x) class(x) head(x)