How to access a list of tibble to check whether “UTF-8” and run import RHow to check whether a file is valid UTF-8?How to get UTF-8 working in Java webapps?The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframeHow can I import a database with MySQL from terminal?How do I import an SQL file using the command line in MySQL?R is the encoding readLines uses dependent on any meta-information of the .txt file?Tibble: operation on list columnsAccess last element in a list within a tibbleUnnest column of a tibble with a list with tibbles in Rhow to import tibble in a package
nginx serves wrong domain site. It doenst shows default site if no configuration applies
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
How do Windows version numbers work?
What would be the ideal melee weapon made of "Phase Metal"?
How to check the quality of an audio sample?
Ways to express "The reader may wish to..." / "The reader may want to..."
Find the wrong number in the given series: 6, 12, 21, 36, 56, 81?
How to make 1,1-diphenyl-1-butene from benzophenone and 1-bromopropane?
Draw 3D Cubes around centre
Are local nested functions possible in elisp?
Is a public company able to check out who owns its shares in very detailed format?
How can one write good dialogue in a story without sounding wooden?
How does one stock fund's charge of 1% more in operating expenses than another fund lower expected returns by 10%?
Historic symbols representing peasants/oppressed persons fighting back?
What would the EU do if an EU member declared war on another EU member?
Why did the Japanese attack the Aleutians at the same time as Midway?
How did the Game Boy Advance stretch Game Boy games to widescreen?
Mbed Cortex-m hardfault when sending data via TCP
Why does the autopilot disengage even when it does not receive pilot input?
Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?
Why limit to revolvers?
Cutting machine can't read vectors with strokes
How can an advanced civilization forget how to manufacture its technology?
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
How to access a list of tibble to check whether “UTF-8” and run import R
How to check whether a file is valid UTF-8?How to get UTF-8 working in Java webapps?The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframeHow can I import a database with MySQL from terminal?How do I import an SQL file using the command line in MySQL?R is the encoding readLines uses dependent on any meta-information of the .txt file?Tibble: operation on list columnsAccess last element in a list within a tibbleUnnest column of a tibble with a list with tibbles in Rhow to import tibble in a package
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
TARGET :
Check whether a list of files have same encoding before import and rbind ,if not the same STOP run
# files list & check encoding
FL_PATH <- list.files(path,pattern = "*.csv",full.name = T)
library(readr)
lapply(FL_PATH,guess_encoding)
# if there is "UTF-8" , STOP RUN , if "Shift_JIS" , RUN the next scripts below :
# import
library(rio)
DT <- rbindlist(lapply(FL_PATH ,import,sep=",",setclass = "data.table"))
# OVER 500 rows to run if the files are same encoding to rbind
DT[,"NEW_COL":="A"]
DT[,"NEW_COL_2":="B"]
.....
# result of --lapply(FL_PATH,guess_encoding)
> lapply(FL_PATH,guess_encoding)
[[1]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 Shift_JIS 0.8
2 GB18030 0.76
3 Big5 0.46
[[2]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 GB18030 0.82
2 UTF-8 0.8
3 Big5 0.44
Problem 1 : How to access the variables of the result of lapply readr
to detect UTF-8 and STOP (have to revise the encoding outside R if
UTF-8 exist ?)
Problem 2 : How to connect the large numbers of normal processing scripts
with "if & STOP run" ?
r utf-8 import tibble readr
add a comment |
TARGET :
Check whether a list of files have same encoding before import and rbind ,if not the same STOP run
# files list & check encoding
FL_PATH <- list.files(path,pattern = "*.csv",full.name = T)
library(readr)
lapply(FL_PATH,guess_encoding)
# if there is "UTF-8" , STOP RUN , if "Shift_JIS" , RUN the next scripts below :
# import
library(rio)
DT <- rbindlist(lapply(FL_PATH ,import,sep=",",setclass = "data.table"))
# OVER 500 rows to run if the files are same encoding to rbind
DT[,"NEW_COL":="A"]
DT[,"NEW_COL_2":="B"]
.....
# result of --lapply(FL_PATH,guess_encoding)
> lapply(FL_PATH,guess_encoding)
[[1]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 Shift_JIS 0.8
2 GB18030 0.76
3 Big5 0.46
[[2]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 GB18030 0.82
2 UTF-8 0.8
3 Big5 0.44
Problem 1 : How to access the variables of the result of lapply readr
to detect UTF-8 and STOP (have to revise the encoding outside R if
UTF-8 exist ?)
Problem 2 : How to connect the large numbers of normal processing scripts
with "if & STOP run" ?
r utf-8 import tibble readr
1
Instead of going through all the results, how about lettinglapply
return only the top result? Trysapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24
add a comment |
TARGET :
Check whether a list of files have same encoding before import and rbind ,if not the same STOP run
# files list & check encoding
FL_PATH <- list.files(path,pattern = "*.csv",full.name = T)
library(readr)
lapply(FL_PATH,guess_encoding)
# if there is "UTF-8" , STOP RUN , if "Shift_JIS" , RUN the next scripts below :
# import
library(rio)
DT <- rbindlist(lapply(FL_PATH ,import,sep=",",setclass = "data.table"))
# OVER 500 rows to run if the files are same encoding to rbind
DT[,"NEW_COL":="A"]
DT[,"NEW_COL_2":="B"]
.....
# result of --lapply(FL_PATH,guess_encoding)
> lapply(FL_PATH,guess_encoding)
[[1]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 Shift_JIS 0.8
2 GB18030 0.76
3 Big5 0.46
[[2]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 GB18030 0.82
2 UTF-8 0.8
3 Big5 0.44
Problem 1 : How to access the variables of the result of lapply readr
to detect UTF-8 and STOP (have to revise the encoding outside R if
UTF-8 exist ?)
Problem 2 : How to connect the large numbers of normal processing scripts
with "if & STOP run" ?
r utf-8 import tibble readr
TARGET :
Check whether a list of files have same encoding before import and rbind ,if not the same STOP run
# files list & check encoding
FL_PATH <- list.files(path,pattern = "*.csv",full.name = T)
library(readr)
lapply(FL_PATH,guess_encoding)
# if there is "UTF-8" , STOP RUN , if "Shift_JIS" , RUN the next scripts below :
# import
library(rio)
DT <- rbindlist(lapply(FL_PATH ,import,sep=",",setclass = "data.table"))
# OVER 500 rows to run if the files are same encoding to rbind
DT[,"NEW_COL":="A"]
DT[,"NEW_COL_2":="B"]
.....
# result of --lapply(FL_PATH,guess_encoding)
> lapply(FL_PATH,guess_encoding)
[[1]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 Shift_JIS 0.8
2 GB18030 0.76
3 Big5 0.46
[[2]]
# A tibble: 3 x 2
encoding confidence
<chr> <dbl>
1 GB18030 0.82
2 UTF-8 0.8
3 Big5 0.44
Problem 1 : How to access the variables of the result of lapply readr
to detect UTF-8 and STOP (have to revise the encoding outside R if
UTF-8 exist ?)
Problem 2 : How to connect the large numbers of normal processing scripts
with "if & STOP run" ?
r utf-8 import tibble readr
r utf-8 import tibble readr
asked Mar 26 at 5:19
ranerane
3171 gold badge2 silver badges10 bronze badges
3171 gold badge2 silver badges10 bronze badges
1
Instead of going through all the results, how about lettinglapply
return only the top result? Trysapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24
add a comment |
1
Instead of going through all the results, how about lettinglapply
return only the top result? Trysapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24
1
1
Instead of going through all the results, how about letting
lapply
return only the top result? Try sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Instead of going through all the results, how about letting
lapply
return only the top result? Try sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24
add a comment |
1 Answer
1
active
oldest
votes
First, get the most probable encoding:
enc <- sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
Then, if any of the files are UTF-8, stop execution.
if(any(grepl('UTF-8',enc)))
stop('UTF-8 present') # This will stop with an error if true
# Now, read files and rbind
dlist <- lapply(FL_PATH,read_csv)
DT <- rbindlist(dlist)
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
add a comment |
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%2f55350318%2fhow-to-access-a-list-of-tibble-to-check-whether-utf-8-and-run-import-r%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, get the most probable encoding:
enc <- sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
Then, if any of the files are UTF-8, stop execution.
if(any(grepl('UTF-8',enc)))
stop('UTF-8 present') # This will stop with an error if true
# Now, read files and rbind
dlist <- lapply(FL_PATH,read_csv)
DT <- rbindlist(dlist)
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
add a comment |
First, get the most probable encoding:
enc <- sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
Then, if any of the files are UTF-8, stop execution.
if(any(grepl('UTF-8',enc)))
stop('UTF-8 present') # This will stop with an error if true
# Now, read files and rbind
dlist <- lapply(FL_PATH,read_csv)
DT <- rbindlist(dlist)
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
add a comment |
First, get the most probable encoding:
enc <- sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
Then, if any of the files are UTF-8, stop execution.
if(any(grepl('UTF-8',enc)))
stop('UTF-8 present') # This will stop with an error if true
# Now, read files and rbind
dlist <- lapply(FL_PATH,read_csv)
DT <- rbindlist(dlist)
First, get the most probable encoding:
enc <- sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
Then, if any of the files are UTF-8, stop execution.
if(any(grepl('UTF-8',enc)))
stop('UTF-8 present') # This will stop with an error if true
# Now, read files and rbind
dlist <- lapply(FL_PATH,read_csv)
DT <- rbindlist(dlist)
answered Mar 26 at 8:52
RohitRohit
1,2588 silver badges12 bronze badges
1,2588 silver badges12 bronze badges
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
add a comment |
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
My god , best way to apply if and STOP and checking function in the whole script
– rane
Mar 26 at 9:04
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
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%2f55350318%2fhow-to-access-a-list-of-tibble-to-check-whether-utf-8-and-run-import-r%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
1
Instead of going through all the results, how about letting
lapply
return only the top result? Trysapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])
– Rohit
Mar 26 at 7:03
Thankyou Rohit , thats exactly the way to ACCESS tibble , and readr raise the first one as highest percentage . But lets say grepl("UTF-8",sapply(FL_PATH,function(x) guess_encoding(x)$encoding[1])) return me TRUE and FALSE , i have no idea how to connect to import / not import approach .
– rane
Mar 26 at 8:24