How can I use R to substitute base names of files in a script for CMD?
I would like to use R to go into a text document I have and iteratively substitute the base name of the files in the first two lines (input and output) with those from a list I have stored in R. The text file looks like this:
parameter input "C:Usersinputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter output "C:Usersoutputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter meshsize 60.0
parameter zlength 500.0
parameter zelem 10
runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem
The idea is to replace the input and output files (they should be identical names since they are stored in different directories) and then send the script to run in CMD. Then repeat the loop with the next file name in the list, which looks like this in R:
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
I've never used R for systems stuff before. Is this possible?
r substitution systems-programming
add a comment |
I would like to use R to go into a text document I have and iteratively substitute the base name of the files in the first two lines (input and output) with those from a list I have stored in R. The text file looks like this:
parameter input "C:Usersinputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter output "C:Usersoutputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter meshsize 60.0
parameter zlength 500.0
parameter zelem 10
runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem
The idea is to replace the input and output files (they should be identical names since they are stored in different directories) and then send the script to run in CMD. Then repeat the loop with the next file name in the list, which looks like this in R:
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
I've never used R for systems stuff before. Is this possible?
r substitution systems-programming
What have you tried so far? Eventually you can usepaste0()andsystem()
– jogo
Nov 21 '18 at 21:41
add a comment |
I would like to use R to go into a text document I have and iteratively substitute the base name of the files in the first two lines (input and output) with those from a list I have stored in R. The text file looks like this:
parameter input "C:Usersinputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter output "C:Usersoutputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter meshsize 60.0
parameter zlength 500.0
parameter zelem 10
runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem
The idea is to replace the input and output files (they should be identical names since they are stored in different directories) and then send the script to run in CMD. Then repeat the loop with the next file name in the list, which looks like this in R:
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
I've never used R for systems stuff before. Is this possible?
r substitution systems-programming
I would like to use R to go into a text document I have and iteratively substitute the base name of the files in the first two lines (input and output) with those from a list I have stored in R. The text file looks like this:
parameter input "C:Usersinputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter output "C:Usersoutputdirectory20090522_104644_r2_0_DVJ_50.k"
parameter meshsize 60.0
parameter zlength 500.0
parameter zelem 10
runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem
The idea is to replace the input and output files (they should be identical names since they are stored in different directories) and then send the script to run in CMD. Then repeat the loop with the next file name in the list, which looks like this in R:
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
I've never used R for systems stuff before. Is this possible?
r substitution systems-programming
r substitution systems-programming
edited Nov 21 '18 at 21:45
jogo
9,85692135
9,85692135
asked Nov 21 '18 at 20:56
hmnoidkhmnoidk
978
978
What have you tried so far? Eventually you can usepaste0()andsystem()
– jogo
Nov 21 '18 at 21:41
add a comment |
What have you tried so far? Eventually you can usepaste0()andsystem()
– jogo
Nov 21 '18 at 21:41
What have you tried so far? Eventually you can use
paste0() and system()– jogo
Nov 21 '18 at 21:41
What have you tried so far? Eventually you can use
paste0() and system()– jogo
Nov 21 '18 at 21:41
add a comment |
1 Answer
1
active
oldest
votes
This is the way you can do that:
s0 <-
c('parameter input "C:\Users\inputdirectory\"',
'parameter output "C:\Users\outputdirectory\"',
'parameter meshsize 60.0',
'parameter zlength 500.0',
'parameter zelem 10',
'runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem')
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
for (file in flist) {
s <- s0
s[1:2] <- paste0(s[1:2], file)
sapply(s, system)
}
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
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%2f53420367%2fhow-can-i-use-r-to-substitute-base-names-of-files-in-a-script-for-cmd%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
This is the way you can do that:
s0 <-
c('parameter input "C:\Users\inputdirectory\"',
'parameter output "C:\Users\outputdirectory\"',
'parameter meshsize 60.0',
'parameter zlength 500.0',
'parameter zelem 10',
'runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem')
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
for (file in flist) {
s <- s0
s[1:2] <- paste0(s[1:2], file)
sapply(s, system)
}
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
add a comment |
This is the way you can do that:
s0 <-
c('parameter input "C:\Users\inputdirectory\"',
'parameter output "C:\Users\outputdirectory\"',
'parameter meshsize 60.0',
'parameter zlength 500.0',
'parameter zelem 10',
'runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem')
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
for (file in flist) {
s <- s0
s[1:2] <- paste0(s[1:2], file)
sapply(s, system)
}
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
add a comment |
This is the way you can do that:
s0 <-
c('parameter input "C:\Users\inputdirectory\"',
'parameter output "C:\Users\outputdirectory\"',
'parameter meshsize 60.0',
'parameter zlength 500.0',
'parameter zelem 10',
'runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem')
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
for (file in flist) {
s <- s0
s[1:2] <- paste0(s[1:2], file)
sapply(s, system)
}
This is the way you can do that:
s0 <-
c('parameter input "C:\Users\inputdirectory\"',
'parameter output "C:\Users\outputdirectory\"',
'parameter meshsize 60.0',
'parameter zlength 500.0',
'parameter zelem 10',
'runscript "meshoutline.scl" &input &output &meshsize &zlength &zelem')
flist <- c("20080715_160601_es_2_KOE_50", "20080806_162049_es_0_JSX_50", "20080810_004229_es_0_WIB_50")
for (file in flist) {
s <- s0
s[1:2] <- paste0(s[1:2], file)
sapply(s, system)
}
answered Nov 21 '18 at 21:53
jogojogo
9,85692135
9,85692135
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
add a comment |
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
I think what this code is trying to do is run each line of s0 through CMD. S0 needs to be saved as its own text file and run through CMD as that, rather than by line.
– hmnoidk
Nov 22 '18 at 19:13
add a comment |
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%2f53420367%2fhow-can-i-use-r-to-substitute-base-names-of-files-in-a-script-for-cmd%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
What have you tried so far? Eventually you can use
paste0()andsystem()– jogo
Nov 21 '18 at 21:41