rlowercase

how to lowercase true and false in csv files in R


I want to ask if there is any way to lowercase 'TRUE' and 'FALSE' in csv files in R. I have tried tolower() function but every time I open the files, 'true' and 'false' are still in upper case, while I need them to be in lowercase as other words.

I hope to receive some help about this. Many thanks!


Solution

  • I think this isn't an R problem. If I convert the text to lower and then look at the data frame, the values are in lower case.

    d <- data.frame(x = c(TRUE, FALSE))
    d$x <- tolower(as.character(d$x))
    d
    #>       x
    #> 1  true
    #> 2 false
    write.csv(d, file="test.csv")
    

    Created on 2025-02-04 with reprex v2.1.1

    If I open the .csv up as a text file in a text editor (like the one in RStudio), I ge the following:

    image of correct css file

    As you can see, in the file these are lower-cased. However, I think the problem comes when opening the file in excel - that converts them to upper case.

    excel image with capitalized values

    It seems like this is a problem with how excel opens the file rather than with how R saves it.