knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(shiny.CSVImport)
library(knitr)

What It Does

The CSV import module provides a standard user interface to read and convert a CSV file according to the users' and the apps' needs. Having selected a file, the module displays the available columns and the associated data types. The user can change the data type and specify the required format required to interpret the data correctly.

The User Interface

Users can specify the general format of the CSV file:

  1. Does the CSV file have a column header describing variable names? Yes/No
  2. Which character separates the columns?
  3. The decimal separator
  4. Date format
  5. time format
  6. A character to qualify text

The package comes along with it's own translations. These languages are currently available:

  1. English
  2. German - Deutsch
  3. Spanish - Español (draft - I would appreciate any help here)
  4. Russian - Русский (draft - I would appreciate any help here)
  5. Korean - 한국어 (rough draft - any help appreciated)

The Spanish and Russian translation most likely need some improvement but should be clear enough to use (no promises, though).

Available Settings

When calling the module an application can provide many options as arguments.

Available data types are based on the capabilities of the readr package:

The type double is available but impractical to use when importing from CSV. The module will only be able to parse these numbers when they do not have a thousands separator. It is safer to use number.

Two further data types have been defined that search for certain patterns in the data and return a logical value depending on the result of the search:

Calling the Module

The call is simple and (consistent with Shiny) you can choose any module Id.

ModuleImportUI("ProjectDataFile")
ModuleImportServer("ProjectDataFile")

User Interface of the Shiny CSV Module{width="75%"}

Specify Date & Time Format

The module depends on the capabilities of R. Thus, it uses the POSIX syntax to specify the expected format of date and time values.

TimeFormats <- read.table(sep = ";", header = TRUE, 
  text = "Code;Meaning; Example
  %a;Abbreviated weekday;Mon
  %A;Full weekday;  Monday
  %b;Abbreviated month; Jan
  %B;Full month; January
  %c;Locale-specific date and time;
  %d;Decimal date;
  %H;Decimal hours (24 hour); 14
  %I;Decimal hours (12 hour); 02
  %j;Decimal day of the year; 
  %m;Decimal month; 6 (June)
  %M;Decimal minute; 22
  %p;Locale-specific AM/PM; 
  %S;Decimal second; 56
  %U;Decimal week of the year (starting on Sunday); 3
  %w;Decimal Weekday (0=Sunday); 0
  %W;Decimal week of the year (starting on Monday); 1
  %x;Locale-specific Date;
  %X;Locale-specific Time;
  %y;2-digit year; 12
  %Y;4-digit year; 2012
  %z;Offset from GMT;
  %Z;Time zone (character);UST")
knitr::kable(
  TimeFormats
)

A few examples:

  x <- strptime(c("2020-01-24 16:07:52.12345"), "%Y-%m-%d %H:%M:%OS")

  # Dates
  format(x, "%Y-%m-%d")     # yyyy-mm-dd
  format(x, "%Y-%j")        # yyyy-[day of year]
  format(x, "%Y-W%V-%u")    # 
  format(x, "%B, %d is in CW%V") # dddd, dd is in CW[week]

  # Time
  format(x, "%H:%M:%S")
  format(x, "%I:%M:%OS4 %p") # "am/pm" will be missing because this has run on a German system

  # Test am/pm
  format(x, "%G-W%V-%u")

{width="25%"}



SigurdJanson/shinyCSVImpoMod documentation built on Jan. 5, 2023, 3:57 a.m.