Question: How to load data into R from an external hard drive?
0
gravatar for M.O.L.S
15 months ago by
M.O.L.S10
M.O.L.S10 wrote:

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.

=)

rstudio unix load R • 3.1k views
ADD COMMENTlink modified 15 months ago by zx87549.1k • written 15 months ago by M.O.L.S10
1

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 REPLYlink modified 15 months ago • written 15 months ago by genomax80k

What OS are you using?

ADD REPLYlink written 15 months ago by genomax80k
1

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 REPLYlink written 15 months ago by steve2.5k

MacOS High Sierra version 10.13.6

ADD REPLYlink written 15 months ago by M.O.L.S10
1
gravatar for M.O.L.S
15 months ago by
M.O.L.S10
M.O.L.S10 wrote:

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 COMMENTlink modified 15 months ago • written 15 months ago by M.O.L.S10
2

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 REPLYlink modified 15 months ago • written 15 months ago by ATpoint31k

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 REPLYlink written 15 months ago by steve2.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1063 users visited in the last hour