add variable in glob2rx function in r












0














I want to get an expression and then put it in the glob2rx function, like:



glob2rx("*A*cfs*")
glob2rx("*B*cfs*")
glob2rx("*C*cfs*")
glob2rx("*D*cfs*")


because I want to use this expression to list file in folder, like:



list.files(pattern=glob2rx("*A*cfs*"))


I want to add a vector like:(looping through df)



 df <- c("A","B","C","D")
ef <- paste0(""","*",df[i],"*","cfs","*")
list.files(pattern=glob2rx(ef))


But It did not work.



Could you give me some hints?










share|improve this question
























  • What does i stand for? Are you looping through df?
    – Vivek Kalyanarangan
    Nov 21 at 5:50










  • Yes. I want to loop through df. Sorry for this late reply.
    – Love_qq_xq
    Nov 22 at 3:14


















0














I want to get an expression and then put it in the glob2rx function, like:



glob2rx("*A*cfs*")
glob2rx("*B*cfs*")
glob2rx("*C*cfs*")
glob2rx("*D*cfs*")


because I want to use this expression to list file in folder, like:



list.files(pattern=glob2rx("*A*cfs*"))


I want to add a vector like:(looping through df)



 df <- c("A","B","C","D")
ef <- paste0(""","*",df[i],"*","cfs","*")
list.files(pattern=glob2rx(ef))


But It did not work.



Could you give me some hints?










share|improve this question
























  • What does i stand for? Are you looping through df?
    – Vivek Kalyanarangan
    Nov 21 at 5:50










  • Yes. I want to loop through df. Sorry for this late reply.
    – Love_qq_xq
    Nov 22 at 3:14
















0












0








0







I want to get an expression and then put it in the glob2rx function, like:



glob2rx("*A*cfs*")
glob2rx("*B*cfs*")
glob2rx("*C*cfs*")
glob2rx("*D*cfs*")


because I want to use this expression to list file in folder, like:



list.files(pattern=glob2rx("*A*cfs*"))


I want to add a vector like:(looping through df)



 df <- c("A","B","C","D")
ef <- paste0(""","*",df[i],"*","cfs","*")
list.files(pattern=glob2rx(ef))


But It did not work.



Could you give me some hints?










share|improve this question















I want to get an expression and then put it in the glob2rx function, like:



glob2rx("*A*cfs*")
glob2rx("*B*cfs*")
glob2rx("*C*cfs*")
glob2rx("*D*cfs*")


because I want to use this expression to list file in folder, like:



list.files(pattern=glob2rx("*A*cfs*"))


I want to add a vector like:(looping through df)



 df <- c("A","B","C","D")
ef <- paste0(""","*",df[i],"*","cfs","*")
list.files(pattern=glob2rx(ef))


But It did not work.



Could you give me some hints?







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 3:15

























asked Nov 21 at 3:19









Love_qq_xq

185




185












  • What does i stand for? Are you looping through df?
    – Vivek Kalyanarangan
    Nov 21 at 5:50










  • Yes. I want to loop through df. Sorry for this late reply.
    – Love_qq_xq
    Nov 22 at 3:14




















  • What does i stand for? Are you looping through df?
    – Vivek Kalyanarangan
    Nov 21 at 5:50










  • Yes. I want to loop through df. Sorry for this late reply.
    – Love_qq_xq
    Nov 22 at 3:14


















What does i stand for? Are you looping through df?
– Vivek Kalyanarangan
Nov 21 at 5:50




What does i stand for? Are you looping through df?
– Vivek Kalyanarangan
Nov 21 at 5:50












Yes. I want to loop through df. Sorry for this late reply.
– Love_qq_xq
Nov 22 at 3:14






Yes. I want to loop through df. Sorry for this late reply.
– Love_qq_xq
Nov 22 at 3:14














1 Answer
1






active

oldest

votes


















0














You're not closing with a ". When you're looping, you can use



path <- getwd()
df <- c("A","B","C","D")
for(i in 1:length(df)){
ef <- paste0("*",df[i],"*","cfs","*")
list.files(path=path,glob2rx(pattern=ef))
}





share|improve this answer























  • Thanks for your answer. But it does not work. Return character(0).
    – Love_qq_xq
    Nov 22 at 3:46












  • Ah yes. Removed quotation marks and added path. That works here locally
    – CIAndrews
    Nov 22 at 3:58










  • Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
    – Love_qq_xq
    Nov 22 at 4:17










  • I edited the answer, the quotation marks in the beginning, the "
    – CIAndrews
    Nov 22 at 4:50










  • great. It works well. Thank you so much.
    – Love_qq_xq
    Nov 22 at 5:31











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404796%2fadd-variable-in-glob2rx-function-in-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









0














You're not closing with a ". When you're looping, you can use



path <- getwd()
df <- c("A","B","C","D")
for(i in 1:length(df)){
ef <- paste0("*",df[i],"*","cfs","*")
list.files(path=path,glob2rx(pattern=ef))
}





share|improve this answer























  • Thanks for your answer. But it does not work. Return character(0).
    – Love_qq_xq
    Nov 22 at 3:46












  • Ah yes. Removed quotation marks and added path. That works here locally
    – CIAndrews
    Nov 22 at 3:58










  • Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
    – Love_qq_xq
    Nov 22 at 4:17










  • I edited the answer, the quotation marks in the beginning, the "
    – CIAndrews
    Nov 22 at 4:50










  • great. It works well. Thank you so much.
    – Love_qq_xq
    Nov 22 at 5:31
















0














You're not closing with a ". When you're looping, you can use



path <- getwd()
df <- c("A","B","C","D")
for(i in 1:length(df)){
ef <- paste0("*",df[i],"*","cfs","*")
list.files(path=path,glob2rx(pattern=ef))
}





share|improve this answer























  • Thanks for your answer. But it does not work. Return character(0).
    – Love_qq_xq
    Nov 22 at 3:46












  • Ah yes. Removed quotation marks and added path. That works here locally
    – CIAndrews
    Nov 22 at 3:58










  • Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
    – Love_qq_xq
    Nov 22 at 4:17










  • I edited the answer, the quotation marks in the beginning, the "
    – CIAndrews
    Nov 22 at 4:50










  • great. It works well. Thank you so much.
    – Love_qq_xq
    Nov 22 at 5:31














0












0








0






You're not closing with a ". When you're looping, you can use



path <- getwd()
df <- c("A","B","C","D")
for(i in 1:length(df)){
ef <- paste0("*",df[i],"*","cfs","*")
list.files(path=path,glob2rx(pattern=ef))
}





share|improve this answer














You're not closing with a ". When you're looping, you can use



path <- getwd()
df <- c("A","B","C","D")
for(i in 1:length(df)){
ef <- paste0("*",df[i],"*","cfs","*")
list.files(path=path,glob2rx(pattern=ef))
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 3:57

























answered Nov 22 at 3:39









CIAndrews

30317




30317












  • Thanks for your answer. But it does not work. Return character(0).
    – Love_qq_xq
    Nov 22 at 3:46












  • Ah yes. Removed quotation marks and added path. That works here locally
    – CIAndrews
    Nov 22 at 3:58










  • Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
    – Love_qq_xq
    Nov 22 at 4:17










  • I edited the answer, the quotation marks in the beginning, the "
    – CIAndrews
    Nov 22 at 4:50










  • great. It works well. Thank you so much.
    – Love_qq_xq
    Nov 22 at 5:31


















  • Thanks for your answer. But it does not work. Return character(0).
    – Love_qq_xq
    Nov 22 at 3:46












  • Ah yes. Removed quotation marks and added path. That works here locally
    – CIAndrews
    Nov 22 at 3:58










  • Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
    – Love_qq_xq
    Nov 22 at 4:17










  • I edited the answer, the quotation marks in the beginning, the "
    – CIAndrews
    Nov 22 at 4:50










  • great. It works well. Thank you so much.
    – Love_qq_xq
    Nov 22 at 5:31
















Thanks for your answer. But it does not work. Return character(0).
– Love_qq_xq
Nov 22 at 3:46






Thanks for your answer. But it does not work. Return character(0).
– Love_qq_xq
Nov 22 at 3:46














Ah yes. Removed quotation marks and added path. That works here locally
– CIAndrews
Nov 22 at 3:58




Ah yes. Removed quotation marks and added path. That works here locally
– CIAndrews
Nov 22 at 3:58












Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
– Love_qq_xq
Nov 22 at 4:17




Which quotation marks should I remove? Can you give me an example? Thanks for your patience.
– Love_qq_xq
Nov 22 at 4:17












I edited the answer, the quotation marks in the beginning, the "
– CIAndrews
Nov 22 at 4:50




I edited the answer, the quotation marks in the beginning, the "
– CIAndrews
Nov 22 at 4:50












great. It works well. Thank you so much.
– Love_qq_xq
Nov 22 at 5:31




great. It works well. Thank you so much.
– Love_qq_xq
Nov 22 at 5:31


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404796%2fadd-variable-in-glob2rx-function-in-r%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python