read_excel won't trim whitespace

Viewed 2701

I am using the package readxl to load an excel file. As default it should strip the white space however it is not doing so.

The file can be downloaded directly from the link below or alternatively it can be downloaded through the website where it is Appendix B

http://www2.nationalgrid.com/UK/Industry-information/Future-of-Energy/Electricity-Ten-Year-Statement/

http://www2.nationalgrid.com/WorkArea/DownloadAsset.aspx?id=8589937799

require(readxl);require(tidyverse)
test <- read_excel("ETYS 2016 Appendix B.xlsx", skip = 1, sheet = 22, trim_ws = TRUE)
print(test$`MVAr Generation`)
test$`MVAr Generation` %>% str_count(patter = "\\s")

test$`MVAr Generation` %>% table #all are numeric
test$`MVAr Generation` %>% class #however the class is characer

test$`MVAr Generation` %>% str_count(patter = "\\s") %>%
sum(na.rm = T) #It should be 0 however it is 2 

This problem is causing problems in the analysis as can be seen by this example in which the numeric column is a character. Help would be appreciated

3 Answers
Related