Like in most other languages R too provides some interfaces to read data and they are called connection interfaces. These connections can be made to different things. Lets try to understand few connections.
- file – make connection to a file
- url – make connection to url
- gzfile, bzfile – make connection to compressed files
File Connection
In R function we need to deal with lot of arguments. But most of the function name and arguments are very straightforward. If you want to a get clear understanding of the arguments you can checkout in the manuals and it’s documented clearly.
In my ‘Read/Write Data into ‘R’ Language’ post I was talking about some useful essential functions where we didn’t use any file connection code. Because we don’t need to deal with connections directly as many functions have implemented to run inside them. So when we are reading and writing a file we don’t need to think much about it.
Lets look at the below code and try to understand to create a connection with the file.
URL Connection
The readLines() function is a useful once you have made the connection with the data location. Therefore, after creating the URL connection using readLines() function we will be able to read the webpages line by line.
Connection to Compressed
To open .gz file we can use gzfile() interface.
Once we open the compressed file using the connection interface we can use readLines() function to read the content line by line from the text files.