Automate data substitution in a data frame
I am reading a tab-separated .txt file with two fields of data (V1 and V2) into RStudio using read.table
V1 V2
Ndepmax 3000
intx 6
Sdepmax 3000
inty 6
This .txt file contains a list of parameter values that will be used as input to an .exe that will be run from RStudio using the system()
command available in base R
I would like to iterate running this .exe with different values for Ndepmax
I am planning to pull the values for Ndepmax
from another data table by looping through a list of spec_num
values and using the vlookup
command from the expss
package
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
I have not been able to determine how to take these iterative values of maxNdep
and use them to replace the value for Ndepmax
in the input file that will be passed to the .exe using system()
Any advice for how to accomplish this substitution would be very much appreciated.
EDIT: Further code/clarification is included below...
# Input parameter file to use for building the string for "clf_cmd"
in_file = read.table("input.txt")
head(in_file, 4)
V1 V2
1 Ndepmax 3000
2 intx 6
3 Sdepmax 3000
4 inty 6
# File containing min/max Ndep
MinMaxNdep = read.table(MinMaxNdep, header = TRUE)
head (MinMaxNdep, 1)
SPNUM NDEP30_min NDEP30_max
1 33786 12.7265 22.7265
# Identify species of interest
# I will ultimately loop through a set of spec_num values, but just starting with a single species for now
spec_num <- MinMaxNdep$SPNUM[1]
# Define maxNdep value to use for substitution into `in_file`
library(expss)
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
# Substitute value of maxNdep for the value of Ndepmax included in the `in_file` data frame
# Not sure how to do this???
# Need to replace the value of 3000 for Ndepmax in the `in_file` data frame with the maxNdep value included in `MinMaxNdep` for spec_num = 33786
# string passed to cmd line for running the .exe
clf <- system((paste0("clf i:in_file", spec_num, ".in"))
r
add a comment |
I am reading a tab-separated .txt file with two fields of data (V1 and V2) into RStudio using read.table
V1 V2
Ndepmax 3000
intx 6
Sdepmax 3000
inty 6
This .txt file contains a list of parameter values that will be used as input to an .exe that will be run from RStudio using the system()
command available in base R
I would like to iterate running this .exe with different values for Ndepmax
I am planning to pull the values for Ndepmax
from another data table by looping through a list of spec_num
values and using the vlookup
command from the expss
package
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
I have not been able to determine how to take these iterative values of maxNdep
and use them to replace the value for Ndepmax
in the input file that will be passed to the .exe using system()
Any advice for how to accomplish this substitution would be very much appreciated.
EDIT: Further code/clarification is included below...
# Input parameter file to use for building the string for "clf_cmd"
in_file = read.table("input.txt")
head(in_file, 4)
V1 V2
1 Ndepmax 3000
2 intx 6
3 Sdepmax 3000
4 inty 6
# File containing min/max Ndep
MinMaxNdep = read.table(MinMaxNdep, header = TRUE)
head (MinMaxNdep, 1)
SPNUM NDEP30_min NDEP30_max
1 33786 12.7265 22.7265
# Identify species of interest
# I will ultimately loop through a set of spec_num values, but just starting with a single species for now
spec_num <- MinMaxNdep$SPNUM[1]
# Define maxNdep value to use for substitution into `in_file`
library(expss)
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
# Substitute value of maxNdep for the value of Ndepmax included in the `in_file` data frame
# Not sure how to do this???
# Need to replace the value of 3000 for Ndepmax in the `in_file` data frame with the maxNdep value included in `MinMaxNdep` for spec_num = 33786
# string passed to cmd line for running the .exe
clf <- system((paste0("clf i:in_file", spec_num, ".in"))
r
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
I essentially need to iteratively replace the current value of 3000 forNdepmax
with values from another data table (namedMinMaxNdep
)...working on better describing my code/question...
– viridius
Nov 14 '18 at 16:50
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18
add a comment |
I am reading a tab-separated .txt file with two fields of data (V1 and V2) into RStudio using read.table
V1 V2
Ndepmax 3000
intx 6
Sdepmax 3000
inty 6
This .txt file contains a list of parameter values that will be used as input to an .exe that will be run from RStudio using the system()
command available in base R
I would like to iterate running this .exe with different values for Ndepmax
I am planning to pull the values for Ndepmax
from another data table by looping through a list of spec_num
values and using the vlookup
command from the expss
package
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
I have not been able to determine how to take these iterative values of maxNdep
and use them to replace the value for Ndepmax
in the input file that will be passed to the .exe using system()
Any advice for how to accomplish this substitution would be very much appreciated.
EDIT: Further code/clarification is included below...
# Input parameter file to use for building the string for "clf_cmd"
in_file = read.table("input.txt")
head(in_file, 4)
V1 V2
1 Ndepmax 3000
2 intx 6
3 Sdepmax 3000
4 inty 6
# File containing min/max Ndep
MinMaxNdep = read.table(MinMaxNdep, header = TRUE)
head (MinMaxNdep, 1)
SPNUM NDEP30_min NDEP30_max
1 33786 12.7265 22.7265
# Identify species of interest
# I will ultimately loop through a set of spec_num values, but just starting with a single species for now
spec_num <- MinMaxNdep$SPNUM[1]
# Define maxNdep value to use for substitution into `in_file`
library(expss)
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
# Substitute value of maxNdep for the value of Ndepmax included in the `in_file` data frame
# Not sure how to do this???
# Need to replace the value of 3000 for Ndepmax in the `in_file` data frame with the maxNdep value included in `MinMaxNdep` for spec_num = 33786
# string passed to cmd line for running the .exe
clf <- system((paste0("clf i:in_file", spec_num, ".in"))
r
I am reading a tab-separated .txt file with two fields of data (V1 and V2) into RStudio using read.table
V1 V2
Ndepmax 3000
intx 6
Sdepmax 3000
inty 6
This .txt file contains a list of parameter values that will be used as input to an .exe that will be run from RStudio using the system()
command available in base R
I would like to iterate running this .exe with different values for Ndepmax
I am planning to pull the values for Ndepmax
from another data table by looping through a list of spec_num
values and using the vlookup
command from the expss
package
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
I have not been able to determine how to take these iterative values of maxNdep
and use them to replace the value for Ndepmax
in the input file that will be passed to the .exe using system()
Any advice for how to accomplish this substitution would be very much appreciated.
EDIT: Further code/clarification is included below...
# Input parameter file to use for building the string for "clf_cmd"
in_file = read.table("input.txt")
head(in_file, 4)
V1 V2
1 Ndepmax 3000
2 intx 6
3 Sdepmax 3000
4 inty 6
# File containing min/max Ndep
MinMaxNdep = read.table(MinMaxNdep, header = TRUE)
head (MinMaxNdep, 1)
SPNUM NDEP30_min NDEP30_max
1 33786 12.7265 22.7265
# Identify species of interest
# I will ultimately loop through a set of spec_num values, but just starting with a single species for now
spec_num <- MinMaxNdep$SPNUM[1]
# Define maxNdep value to use for substitution into `in_file`
library(expss)
maxNdep <- vlookup(spec_num, MinMaxNdep, result_column='NDEP30_max')
# Substitute value of maxNdep for the value of Ndepmax included in the `in_file` data frame
# Not sure how to do this???
# Need to replace the value of 3000 for Ndepmax in the `in_file` data frame with the maxNdep value included in `MinMaxNdep` for spec_num = 33786
# string passed to cmd line for running the .exe
clf <- system((paste0("clf i:in_file", spec_num, ".in"))
r
r
edited Nov 15 '18 at 15:49
viridius
asked Nov 14 '18 at 16:22
viridiusviridius
111110
111110
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
I essentially need to iteratively replace the current value of 3000 forNdepmax
with values from another data table (namedMinMaxNdep
)...working on better describing my code/question...
– viridius
Nov 14 '18 at 16:50
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18
add a comment |
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
I essentially need to iteratively replace the current value of 3000 forNdepmax
with values from another data table (namedMinMaxNdep
)...working on better describing my code/question...
– viridius
Nov 14 '18 at 16:50
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
I essentially need to iteratively replace the current value of 3000 for
Ndepmax
with values from another data table (named MinMaxNdep
)...working on better describing my code/question...– viridius
Nov 14 '18 at 16:50
I essentially need to iteratively replace the current value of 3000 for
Ndepmax
with values from another data table (named MinMaxNdep
)...working on better describing my code/question...– viridius
Nov 14 '18 at 16:50
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18
add a comment |
0
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%2f53304642%2fautomate-data-substitution-in-a-data-frame%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
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.
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%2f53304642%2fautomate-data-substitution-in-a-data-frame%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
It is note exactly clear what you want. Please make a minimal reproducible example: share impute files, show your R code running with those files and describe more clearly what the problem is.
– Florian
Nov 14 '18 at 16:40
Ok, I will try to do so, but it may take me a bit. In the meantime, it would be great it anyone can decipher and provide guidance.
– viridius
Nov 14 '18 at 16:43
I essentially need to iteratively replace the current value of 3000 for
Ndepmax
with values from another data table (namedMinMaxNdep
)...working on better describing my code/question...– viridius
Nov 14 '18 at 16:50
Question has been edited to further clarify
– viridius
Nov 14 '18 at 17:18