I have the following like text (csv) files to read, where first four columns are of my interest but after that I have alot of junk. I just want to read first four columns into R.

I want first four columns, so that output (csv opened in excel) would look like:

I could not paste the whole file nor attach it due to limitations of SO. Here is smaller example for workout:
type,latitude,longitude,name,link1,
W,43.075319,-89.386145,Mirch Masala,"<just link, jjksskkls hskks > ","<just link, jjksskkls hskks > "
W,43.07488,-89.390698,Himal Chuli Restaurant,"<just link, jjksskkls hskks > ","<just link, hskks , hsksks > "
W,43.074887,-89.391011,Chautara Restaurant,"<just link, hskks , hsksks > ","<just link, jjksskkls hskks > "
W,43.092866,-89.351587,Dobhan Restaurant,"<just link, jjksskkls hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.074746,-89.393137,State Street Cash Mart,"<just link, jjksskkls hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.072801,-89.395718,Dotty Dumplings Dowry,"<just link, jjksskkls , hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.074744,-89.393046,Dobra Tea,"<just link, jjksskkls hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.076372,-89.380231,Hi-Madison,"<just link, jjksskkls hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.019624,-89.421822,Candlewood Suites Fitchburg,"<just link, jjksskkls , ssjjs hskks > ","<just link, jjksskkls , ssjjs hskks > "
W,43.08154,-89.524094,Holiday Inn Hotel & Suites Madison West,"<just link, jjksskkls 100 hskks > ","<just link, jjksskkls , ssjjs hskks > "
Any idea on just reading first four columns while importing into R ?
Based on your comments to your question, your title is somewhat misleading. Where you’re running into problems is not knowing the exact number of columns your final
data.framewould have.From the
?read.tablehelp page:So, let’s try a different answer.
First, let this represent your data:
(This next step won’t be required from your side if this is already saved as a text or csv file, but for the sake of a minimal reproducible example…)
Write those lines to a text file to simulate the
read.tableprocess:That will create a “ragged” file to be read in using
read.tableorread.csv. The trick, though, is to usecount.fieldsto figure out how many columns the file should have.