adding an `ifelse` like statement or `trycatch` to code for reading in files
I am trying to read in some data using a combination of list.files
etc.
I have a character value called myfiles
and looks like the following;
[1] "E:/IRI Data/External/demos12.csv"
[2] "E:/IRI Data/External/demo8.CSV"
[3] "E:/IRI Data/External/demos10.CSV"
[4] "E:/IRI Data/External/demos11.CSV"
[5] "E:/IRI Data/External/demos9.CSV"
Which has different font sizes for the .csv
formats. I have the following function:
myfiles = lapply(myfiles,
FUN = function(files) {
read.csv(files, header = TRUE)
})
Which reads in the .csv
files, however, I have some lowercase and some uppercase so I am running into errors on line 3 of that function read.csv
- I am trying to expand the function such that if the file does not exits for .csv
lowercase then try .CSV
uppercase.
Any help would be great.
r
|
show 3 more comments
I am trying to read in some data using a combination of list.files
etc.
I have a character value called myfiles
and looks like the following;
[1] "E:/IRI Data/External/demos12.csv"
[2] "E:/IRI Data/External/demo8.CSV"
[3] "E:/IRI Data/External/demos10.CSV"
[4] "E:/IRI Data/External/demos11.CSV"
[5] "E:/IRI Data/External/demos9.CSV"
Which has different font sizes for the .csv
formats. I have the following function:
myfiles = lapply(myfiles,
FUN = function(files) {
read.csv(files, header = TRUE)
})
Which reads in the .csv
files, however, I have some lowercase and some uppercase so I am running into errors on line 3 of that function read.csv
- I am trying to expand the function such that if the file does not exits for .csv
lowercase then try .CSV
uppercase.
Any help would be great.
r
which of the files you want to read? Do you want to avoid reading the.csv
files?
– akrun
Nov 12 at 19:34
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the.csv
lowercase and it stores them as a large list of 5 elements.
– user113156
Nov 12 at 19:37
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
The issue is coming from the file extentions. The lineread.csv(files, header = TRUE)
is only able to read in lowercase.csv
files so when an uppercase.csv
file extention is thrown at it the function breaks.
– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43
|
show 3 more comments
I am trying to read in some data using a combination of list.files
etc.
I have a character value called myfiles
and looks like the following;
[1] "E:/IRI Data/External/demos12.csv"
[2] "E:/IRI Data/External/demo8.CSV"
[3] "E:/IRI Data/External/demos10.CSV"
[4] "E:/IRI Data/External/demos11.CSV"
[5] "E:/IRI Data/External/demos9.CSV"
Which has different font sizes for the .csv
formats. I have the following function:
myfiles = lapply(myfiles,
FUN = function(files) {
read.csv(files, header = TRUE)
})
Which reads in the .csv
files, however, I have some lowercase and some uppercase so I am running into errors on line 3 of that function read.csv
- I am trying to expand the function such that if the file does not exits for .csv
lowercase then try .CSV
uppercase.
Any help would be great.
r
I am trying to read in some data using a combination of list.files
etc.
I have a character value called myfiles
and looks like the following;
[1] "E:/IRI Data/External/demos12.csv"
[2] "E:/IRI Data/External/demo8.CSV"
[3] "E:/IRI Data/External/demos10.CSV"
[4] "E:/IRI Data/External/demos11.CSV"
[5] "E:/IRI Data/External/demos9.CSV"
Which has different font sizes for the .csv
formats. I have the following function:
myfiles = lapply(myfiles,
FUN = function(files) {
read.csv(files, header = TRUE)
})
Which reads in the .csv
files, however, I have some lowercase and some uppercase so I am running into errors on line 3 of that function read.csv
- I am trying to expand the function such that if the file does not exits for .csv
lowercase then try .CSV
uppercase.
Any help would be great.
r
r
asked Nov 12 at 19:33
user113156
7891417
7891417
which of the files you want to read? Do you want to avoid reading the.csv
files?
– akrun
Nov 12 at 19:34
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the.csv
lowercase and it stores them as a large list of 5 elements.
– user113156
Nov 12 at 19:37
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
The issue is coming from the file extentions. The lineread.csv(files, header = TRUE)
is only able to read in lowercase.csv
files so when an uppercase.csv
file extention is thrown at it the function breaks.
– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43
|
show 3 more comments
which of the files you want to read? Do you want to avoid reading the.csv
files?
– akrun
Nov 12 at 19:34
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the.csv
lowercase and it stores them as a large list of 5 elements.
– user113156
Nov 12 at 19:37
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
The issue is coming from the file extentions. The lineread.csv(files, header = TRUE)
is only able to read in lowercase.csv
files so when an uppercase.csv
file extention is thrown at it the function breaks.
– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43
which of the files you want to read? Do you want to avoid reading the
.csv
files?– akrun
Nov 12 at 19:34
which of the files you want to read? Do you want to avoid reading the
.csv
files?– akrun
Nov 12 at 19:34
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the
.csv
lowercase and it stores them as a large list of 5 elements.– user113156
Nov 12 at 19:37
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the
.csv
lowercase and it stores them as a large list of 5 elements.– user113156
Nov 12 at 19:37
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
The issue is coming from the file extentions. The line
read.csv(files, header = TRUE)
is only able to read in lowercase .csv
files so when an uppercase .csv
file extention is thrown at it the function breaks.– user113156
Nov 12 at 19:43
The issue is coming from the file extentions. The line
read.csv(files, header = TRUE)
is only able to read in lowercase .csv
files so when an uppercase .csv
file extention is thrown at it the function breaks.– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43
|
show 3 more comments
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268910%2fadding-an-ifelse-like-statement-or-trycatch-to-code-for-reading-in-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268910%2fadding-an-ifelse-like-statement-or-trycatch-to-code-for-reading-in-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
which of the files you want to read? Do you want to avoid reading the
.csv
files?– akrun
Nov 12 at 19:34
Ah sorry, I am trying to read all of the files using this function. For a similar task I read all of the
.csv
lowercase and it stores them as a large list of 5 elements.– user113156
Nov 12 at 19:37
Where is the issue in reading these files? Are you saying that 2:5 files are not reading
– akrun
Nov 12 at 19:39
The issue is coming from the file extentions. The line
read.csv(files, header = TRUE)
is only able to read in lowercase.csv
files so when an uppercase.csv
file extention is thrown at it the function breaks.– user113156
Nov 12 at 19:43
EDIT: Wait something is working... I will update you ASAP.
– user113156
Nov 12 at 19:43