R wants to load csv file but gets error "Input connection has incorrect input"

Asked 2 years ago, Updated 2 years ago, 96 views

I have a data analysis class using R at the university, so I would like to ask you a question.This is my first question, so I'm sorry if there's anything I don't have.I'm a complete beginner at R.

I'm trying to load the csv file, but I get an error.

Entered expressions

read.csv("~.csv", fileEncoding="utf-8")

error

read.table(file=file, header=header, sep=sep, quote=quote, error: 
   No rows available while typing 
 Additional Information: Warning Message: 
 in read.table(file=file, header=header, sep=sep, quote=quote, and so on: 
   Invalid input in input connection '~.csv'

As for the file, I changed the file attached to the task page (Excel) to csv format and saved it.Is the code bad or is there a problem with the file?If anyone knows how to solve this problem, please let me know.

r csv

2022-09-29 22:16

1 Answers

The following is not the answer, but I will capture the handling of the UTF-8 BOM (Byte Order Mark) in R.

Running help(file) on R and referencing the Encoding section explains:

Encoding:

As from R 3.0.0 the encoding "UTF-8-BOM" is accepted for reading and will remove a Byte Order Mark if present (which it often is for files and webpages generated by Microsoft applications). If a BOM is required (it is not recommended) when writing it should be written explicitly, e.g. by writeChar("\ufeff", con, eos = NULL) or writeBin(as.raw(c(0xef, 0xbb, 0xbf), binary_con)


2022-09-29 22:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.