Read Only Header of File in R
In this article, we are going to see the header of the file in R Programming language.
Method 1: Using read.table method
The read.table() method in R is used to access the contents stored in the organized structure of the CSV file.
Syntax: read.table(path, head = TRUE, nrows, sep = “;”)
- path: The complete directory path where the file is stored
- head: a logical value, indicator of whether the file contains the names of the variables as its first line or not.
- nrows: the maximum number of rows to read into the working directory
 col1 col2 col3 <0 rows> (or 0-length row.names)
Method 2: Using colnames method
The read.csv2() method in R is used to read the CSV file from the specified path argument into a tabular structure.
path: The complete directory path where the file is stored
colnames() method in base R is used to gather the column names assigned to the tabular structure of the CSV file. It takes as argument the tabular structure read from the file.
df: The data frame to read the header of
 "col1" "col2" "col3"