MIS 205

Data Import to and Export from


I. Ozkan, PhD

Professor
MIS
Cankaya University

iozkan@cankaya.edu.tr

Fall 2025

Reference

Learning Objectives for Today’s Class

Data import

Data import: readr package

Data Export

Data Export: readr package

Data Import Using RStudio

Use RStudio Environment menu option

Some Details: Reading CSV Data Files

read_csv(
  file,
  col_names = TRUE,
  col_types = NULL,
  locale = default_locale(),
  na = c("", "NA"),
  quoted_na = TRUE,
  quote = "\"",
  comment = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  progress = show_progress(),
  skip_empty_rows = TRUE
)


An Example: Reading CSV Data

Import csv data shown in R for Data Science (2e), chapter 7:

students <- readr::read_csv(file = "https://akademik.cankaya.edu.tr/~iozkan/mis207/students.csv")

dim(students)
## [1] 6 5
students
## # A tibble: 6 × 5
##   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  
##          <dbl> <chr>            <chr>              <chr>               <chr>
## 1            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    
## 2            2 Barclay Lynn     French fries       Lunch only          5    
## 3            3 Jayendra Lyne    N/A                Breakfast and lunch 7    
## 4            4 Leon Rossini     Anchovies          Lunch only          <NA> 
## 5            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five 
## 6            6 Güvenç Attila    Ice cream          Lunch only          6

Reading Excel Files with readxl Package

Microsoft Excel (with extensions .xlsfor MSFT Excel 2003 and earlier OR .xlsx for MSFT Excel 2007 and later)

read_excel(
  path,
  sheet = NULL,
  range = NULL,
  col_names = TRUE,
  col_types = NULL,
  na = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  progress = readxl_progress(),
  .name_repair = "unique"
)

Reading CSVs with Vroom Package

if(require(vroom)==FALSE) install.packages('vroom')
fast_df <- vroom::vroom("your_file.csv")

Reading Proprietary Binary Files with haven Package

Several functions from the haven can be used to read and write formats used by other statistical packages. Example functions include:

Please refer to the help files for each of those packages for more details.

JavaScript Object Notation: JSON Files

JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays… It is a common data format with diverse uses … including that of web applications with servers. — Wikipedia’s Definition of JSON

JSON Files

JSON

{
  "firstName": "Mickey",
  "lastName": "Mouse",
  "address": {
    "city": "Mousetown",
    "postalCode": 10000
  }
  "logical": [true, false]
}

R list

list(
  firstName = "Mickey",
  lastName = "Mouse",
  address = list(
    city = "Mousetown",
    postalCode = 10000
  ),
  logical = c(TRUE, FALSE)
)

Data export

From Read to Write

read_*() to write_*()

Here are some ideas: do they come from the same package?

write_csv(students, file = "example.csv")
write_sas(students, path = "example.sas7bdat")
write_json(students, path = "example.json")

Summary of Main Points

By now, you should be able to do the following: