Read text File with Space as Delimiter in R Last Updated : 23 Sep, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to read a text file with spaces as delimiters in R programming language. Base R allows us to read and access the content within the text files with any number of characters as the delimiter. File in use: The read.table() method in R can be used to read data from a text file into the data.table or a similar R object. In case the file is located within the same directory, the file-name is specified, else the complete path to the file is given in the workspace. Also, the header is an optional parameter, if TRUE, the header is read into the workspace else, omitted. Syntax: read.table( path-of-the-file, header = T) Example: Read TXT file with spaces as a delimiter R # reading data from the text file file_path <- "r_content.txt" data_table <- read.table(file_path, header = TRUE) print("Contents of the text file") print(data_table) Output: [1] "Contents of the text file" col1 col2 col3 1 1 3 A 2 3 5 B 3 6 8 C 4 8 12 D The "sep" argument is used to specify the delimiter of the text file cell values. The "sep" argument of the data.table can also be used to read a text file containing data with single or multiple spaces as delimiters. The sep = "" is used to refer to any length whitespace as being the delimiter. Syntax: read.table(filepath, sep, header=T, na.strings, stringAsFactors) Example: Read TXT file with spaces as a delimiter R # reading data from the text file file_path <- "r_content.txt" data_table <- read.table(file_path, sep = "" , header = T , na.strings ="", stringsAsFactors= F) print("Contents of the text file") print(data_table) Output: [1] "Contents of the text file" col1 col2 col3 1 1 3 A 2 3 5 B 3 6 8 C 4 8 12 D Comment More infoAdvertise with us Next Article Read Fixed Width Text File in R Y yashchuahan Follow Improve Article Tags : R Language R-FileHandling Similar Reads Read Fixed Width Text File in R In this article, we are going to see how to read fixed-width text files in R Programming language. In text files, columns will have fixed widths, specified in characters, which determines the maximum amount of data it can contain.  No delimiters are used to separate the fields in the file.  Instead 3 min read How To Read Space-Delimited Files In Pandas In this article, We'll learn to efficiently read and process space-delimited files with variable spaces using Pandas in Python.What is a Space-Delimited file?Space-delimited files are a type of text file where data is organized into records (rows) and fields (columns), separated by spaces instead of 4 min read Read all Files in Directory using R To list all files in a directory in R programming language we use list.files(). This function produces a list containing the names of files in the named directory. It returns a character vector containing the names of the files in the specified directories. If no files are present in the directory, 2 min read R Read Text File to DataFrame In today's data-driven world, collecting data from multiple sources and turning it into a structured manner is a critical responsibility for data analysts and scientists. Text files are a prominent source of data, as they frequently include useful information in plain text format. To be used success 5 min read How to read numbers with a comma as decimal separator in R? Handling numeric data correctly is important for accurate data analysis, and one common issue is dealing with different decimal separators. While the dot (.) is commonly used as a decimal separator in English-speaking countries, many European and South American countries use the comma (,). This arti 5 min read How to Use read.delim in R? In this article, we will learn how to use the read.delim() in the R Programming Language. Example 1: Using read.delim() function to read a space-separated text file The read.delim() function is used to read delimited text files in the R Language. It doesn't need any external package to work. This fu 3 min read Like