File open mode error in R (2024)

File open mode error in R

1

Entering edit mode

7.4 years ago

dengziqi1234 ▴ 20

Hello!I'm using a package from github. I've installed it. But when i follow the guideline. I met a error about opening file.

require(rmotifx)rmotifxfg.path = system.file("extdata", "fg-data-ck2.txt", package="motifx")bg.path = system.file("extdata", "bg-data-serine.txt", package="motifx")fg.seqs = readLines(fg.path)Warning message:In file(con, "r") : file("") only supports open = "w+" and open = "w+b": using the formerbg.seqs = readLines(bg.path)Warning message:In file(con, "r") : file("") only supports open = "w+" and open = "w+b": using the formerhead(fg.seqs)character(0)head(bg.seqs)character(0)

Those two file are peptide sequence file. So i need to readLines them. I'm wondering how can i fix it?Thank you!

here's the original tutorial: https://github.com/omarwagih/rmotifx

R data analysis alignment • 4.7k views

ADD COMMENTlink updated 7.4 years ago by ddiez ★ 2.0k • written 7.4 years ago by dengziqi1234 ▴ 20

1

Entering edit mode

Can you edit your post to include your code scripts and the error you are getting in text format?

ADD REPLYlink 7.4 years ago by ecolonaut ▴ 100

1

Entering edit mode

I'm sorry. I've edited it.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Entering edit mode

I can't access that image (403 - Forbidden).

ADD REPLYlink 7.4 years ago by WouterDeCoster 47k

Entering edit mode

Sorry for that. Now i have written them out.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Entering edit mode

I've modified your post using code formatting (the 101010 button).

Can you check the variables fg.path and bg.path and see if the file they point to really exists on your system?

ADD REPLYlink 7.4 years ago by WouterDeCoster 47k

Entering edit mode

Yes, they exists. I put them under the Working Directory.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Entering edit mode

Actually, you don't have an error. Just warnings.

ADD REPLYlink 7.4 years ago by WouterDeCoster 47k

Entering edit mode

ADD REPLYlink 7.4 years ago by cool.abbecker ▴ 30

Entering edit mode

Biostars also has a (probably similar) version of posting guidelines: How To Ask Good Questions On Technical And Scientific Forums

ADD REPLYlink 7.4 years ago by WouterDeCoster 47k

Entering edit mode

Sorry I am new and were not aware of the internal guidelines. I will link them next time. Thanks for the information!

ADD REPLYlink 7.4 years ago by cool.abbecker ▴ 30

Entering edit mode

Thank you for your information.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Entering edit mode

Thank you for information.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

4

Entering edit mode

7.4 years ago

ecolonaut ▴ 100

I believe this is an issue with how you are calling your data, rather than something with the readLines() function. After trying the example on my console I got the same error. The system.files() calls don't work so the objects bg.path and fg.path are empty, and when readLines() tries to search for the .txt files it can't find them. So, you just have to tell R exactly where to find the files you want it to run. You can do this by just including the entire file path in the readLines() call:

fg.seqs = readLines(file("C:/Users/Gregory/Documents/R/win-library/3.3/rmotifx/extdata/fg-data-ck2.txt"))bg.seqs = readLines(file("C:/Users/Gregory/Documents/R/win-library/3.3/rmotifx/extdata/bg-data-serine.txt")) head(fg.seqs)###[1] "KRAGGEESQFEMDI_" "SSYGISETTLEEIFL" "SYGISETTLEEIFLK"###[4] "FLKVAEESGVDAETS" "WSLNKEDTSEQVVPV" "KKLSVPTSDEEDEVP"

*EDIT: You'll need to find the files on your computer and change the path.

ADD COMMENTlink 7.4 years ago by ecolonaut ▴ 100

Entering edit mode

It make sense! Perfect! It works! Thank you very much, Mr.Gregory,I think.

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Entering edit mode

Just a small comment. If you pass the entire path with the filenames as a string, you don't need them to go with a call to file(). That is, readLines("C:/Users/Gregory/Documents/R/win-library/3.3/rmotifx/extdata/fg-data-ck2.txt") should work just as fine.

ADD REPLYlink 7.4 years ago by ddiez ★ 2.0k

4

Entering edit mode

7.4 years ago

ddiez ★ 2.0k

I believe the problem here is very different :-)

Looking for the motifx package (why? because I didn't read the entire question at first, just the call to system.file()...) I found the following github page. In the README file there is an example exactly like the one the OP includes. If I run that example, I get the same error. However, there is an important detail: This R package is not named motifx, but rmotifx! If you consider that fact an run the following code, everything works as expected:

system.file("extdata", "fg-data-ck2.txt", package="rmotifx")[1] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rmotifx/extdata/fg-data-ck2.txt"

So you have to change the parts that refer to motifx for rmotifx. My guess is, the package was once called motifx and the examples on the README file where written then. Later, the package was renamed as rmotifx but the documentation was not updated. Interestingly, the main function, motifx(), maintains its original name.

EDIT

The code in the README file has been fixed.

ADD COMMENTlink 7.4 years ago by ddiez ★ 2.0k

Entering edit mode

You are a attentive man! It works too! Thank you!

ADD REPLYlink 7.4 years ago by dengziqi1234 ▴ 20

Login before adding your answer.

File open mode error in R (2024)
Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 6011

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.