Hi Team, my csv has 60 columns where need to output as character on column id 11 and 12 in readr.
The col_types need to contain all 63 columns specified one by one manually.
My request = as in data.table, I would like to script as col_classes = list(character = c(11, 12)) which are caretype and hospital.
Why not using data.table then? = data.table reads as characters for 'thousand marks numeric columns' in csv. readr, datapasta and vroom are smart and read them as numeric.
However, readr and vroom find it hard to specify just only 2 columns as character.
Repex for the dataset included.
Desired result = column id 11 carethpe and 12 hospital are imported as character, not integer or numeric
Thank you very much.
GK
bucket <- tibble::tribble(
~EncounterNumber, ~drg, ~drg.desc, ~Revenue, ~StartDateTime, ~EndDateTime, ~TotalAmount, ~DirectCost, ~IndirectCost, ~EncounterType, ~CareType, ~Hospital, ~WIES, ~NWAU, ~HAC, ~LengthOfStay, ~rev_minus_cost, ~Discharged, ~WIP, ~fy, ~Lostype, ~age_at_admission, ~Sex, ~unit_label, ~ward_label, ~DischargeElection, ~Admin, ~AlliedHealth, ~AlliedHealthSuppl, ~CCU, ~CCUSuppl, ~COVID, ~COVIDEx, ~ED, ~EDSuppl, ~Exclude, ~HITH, ~HITHSuppl, ~ICU, ~ICUSuppl, ~Imaging, ~ImagingSuppl, ~Medical, ~MedicalSuppl, ~NBA, ~Nursing, ~NursingSuppl, ~Other, ~OthSuppl, ~Pathology, ~PathologySuppl, ~Pharmacy, ~PharmacySuppl, ~PROS, ~PtTransport, ~TheatreNonOR, ~TheatreNonORSuppl, ~TheatreOR, ~TheatreORSuppl, ~CW, ~DH, ~Other, ~Private,
"IP123456", "H64A", "Disorders of the Biliary Tract", 15197.44, "1/07/2023 0:31", "9/07/2023 14:36", 15880.62, 12927.12, 2953.5, "I", 4L, 0L, 0L, 1.7556, "No", 8.587, -683.18, TRUE, "N", "FY24", "multiday", 39L, "M", "LTU", "8W", "Hospital", 729.0939, 75.888, 14.5886, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 596.8591, 135.1964, 2651.49, 584.5504, 0L, 6163.25, 1250.48, 1201.75, 0L, 490.9873, 276.8207, 607.5376, 1054.73, 47.3921, 0L, 0L, 0L, 0L, 0L, 4.9283, 15192.4, 0L, 0.1109
)
bucket %>%
glimpse()
write.csv(bucket, 'bucket.csv', row.names = FALSE)
bucket.readr <- readr::read_csv('bucket.csv', col_types = list(c(11,12) = 'c'))
#> Error in parse(text = input): <text>:10:73: unexpected '='
#> 9:
#> 10: bucket.readr <- readr::read_csv('bucket.csv', col_types = list(c(11,12) =
#> ^
Created on 2025-04-18 with reprex v2.1.1