How to load data into R from an external hard drive?
1
0
Entering edit mode
5.9 years ago
M.O.L.S ▴ 100

Hi

I am analysing biological data using R programming language and R studio.

File > Open File> Memory Stick > / Data > biological_data.txt

allows me to view data in a new window from an external hard drive into R Studio.

My computer is free of files and needs to stay that way because they take up too much space.

Is there a way that I can actually work on this data in RStudio directly from the hard drive?

So far the biological_data.txt file opens up in a new window in R studio, but I do not know how to use it and cannot simply copy and paste the data from the window into the console.

When I type:

help(setwd)

in R, I get a beautiful output saying:

setwd(dir) is used to set the working directory to dir.

However, how can I find the path to the file on the memory stick (external hard drive)? This does not show up on the Terminal or in RStudio.

=)

R load Rstudio unix • 15k views
ADD COMMENT
1
Entering edit mode

Is there a way that I can actually work on this data in R directly from the hard drive?

Look into setwd command. It will allow you to set your working directory to which ever place you want it to be.

ADD REPLY
0
Entering edit mode

What OS are you using?

ADD REPLY
1
Entering edit mode

if you are lucky enough to be using a Mac, you can simply drag the file from the Finder to the Terminal to reveal the full path.

ADD REPLY
0
Entering edit mode

MacOS High Sierra version 10.13.6

ADD REPLY
1
Entering edit mode
5.9 years ago
M.O.L.S ▴ 100

Thank you so much for your invaluable help, It is very much appreciated.

So all in all, the answer is:

In order to analyse data in R or RStudio it is important to use the setwd() command.

setwd(location/on/computer/to/where/the/folder/is/located)

This is which is a one word command to find the path and tell the program to work with the files that are only inside of this folder. The path is the folder where the data is located on the computer. In my case, all the data is on an external hard drive so that I can keep my computer clear and breezy. To find the path from an external memory stick or external hard drive, use the cursor to drag the file from the Finder to the Terminal (on Mac) This reveals the full location of the folder and this is what is copied and pasted into the load() command in R or RStudio.

biological_data <- load("external/hard/drive/where/the/folder/is/biological_data.txt")
ADD COMMENT
2
Entering edit mode

That is not completely true. setwd only defines a folder, nothing more. If you want to load data, lets say a file termed test.bed, you still have to loaded it into R (so into the memory) with any loading command like read.delim, data.table::fread or similar, and for this, it does not matter if you do:

setwd("path/to/workdir")
fread("test.bed")

OR

fread("path/to/workdir/test.bed")

Also load loads an Rdata object that you previously saved to a location on disk (or external disk) with save. I recommend you spend some time getting a solid background in how to work with R before diving into any analysis :)

ADD REPLY
0
Entering edit mode

If you are using Rstudio, its a good idea to use the "Projects" feature in order to keep your working directory set consistently. Generally, using setwd() is a bad practice and will lead to headaches down the road.

ADD REPLY

Login before adding your answer.

Traffic: 1868 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6