Extracting a few bits of data from .txt file












0














After a long morning, I have given up!



I have the following text file: StationLog.txt



Containing the following:



Version      = 2.0
StationName = STN67_P70
BeginTime = 2017-10-06.03:25:00
EndTime = 2017-10-06.03:55:00
IgnoreNo = 5000
PumpedVolume = 0


I need to extract the BeginTime, EndTime and StationName, those headings are fine, as values which feeds into another bit of code.



The idea is I don't have to do it manually as there will be lots of these files in time.



Following various other guides I have to this far:



a <- read.fwf("StationLog.txt", c(37,100), stringsAsFactors=FALSE)
a <- a[grep("=", a$V1), ]
a <- cbind(
do.call( rbind, strsplit(a$V1, "=\s+") )


But hit a bit of a wall, any help would be greatly appreciated!










share|improve this question



























    0














    After a long morning, I have given up!



    I have the following text file: StationLog.txt



    Containing the following:



    Version      = 2.0
    StationName = STN67_P70
    BeginTime = 2017-10-06.03:25:00
    EndTime = 2017-10-06.03:55:00
    IgnoreNo = 5000
    PumpedVolume = 0


    I need to extract the BeginTime, EndTime and StationName, those headings are fine, as values which feeds into another bit of code.



    The idea is I don't have to do it manually as there will be lots of these files in time.



    Following various other guides I have to this far:



    a <- read.fwf("StationLog.txt", c(37,100), stringsAsFactors=FALSE)
    a <- a[grep("=", a$V1), ]
    a <- cbind(
    do.call( rbind, strsplit(a$V1, "=\s+") )


    But hit a bit of a wall, any help would be greatly appreciated!










    share|improve this question

























      0












      0








      0







      After a long morning, I have given up!



      I have the following text file: StationLog.txt



      Containing the following:



      Version      = 2.0
      StationName = STN67_P70
      BeginTime = 2017-10-06.03:25:00
      EndTime = 2017-10-06.03:55:00
      IgnoreNo = 5000
      PumpedVolume = 0


      I need to extract the BeginTime, EndTime and StationName, those headings are fine, as values which feeds into another bit of code.



      The idea is I don't have to do it manually as there will be lots of these files in time.



      Following various other guides I have to this far:



      a <- read.fwf("StationLog.txt", c(37,100), stringsAsFactors=FALSE)
      a <- a[grep("=", a$V1), ]
      a <- cbind(
      do.call( rbind, strsplit(a$V1, "=\s+") )


      But hit a bit of a wall, any help would be greatly appreciated!










      share|improve this question













      After a long morning, I have given up!



      I have the following text file: StationLog.txt



      Containing the following:



      Version      = 2.0
      StationName = STN67_P70
      BeginTime = 2017-10-06.03:25:00
      EndTime = 2017-10-06.03:55:00
      IgnoreNo = 5000
      PumpedVolume = 0


      I need to extract the BeginTime, EndTime and StationName, those headings are fine, as values which feeds into another bit of code.



      The idea is I don't have to do it manually as there will be lots of these files in time.



      Following various other guides I have to this far:



      a <- read.fwf("StationLog.txt", c(37,100), stringsAsFactors=FALSE)
      a <- a[grep("=", a$V1), ]
      a <- cbind(
      do.call( rbind, strsplit(a$V1, "=\s+") )


      But hit a bit of a wall, any help would be greatly appreciated!







      r text automation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 9:59









      Jim

      315




      315
























          3 Answers
          3






          active

          oldest

          votes


















          2














          Based on the read.table function, you can use the arguments to do what you want.



          The following proposal will work if you have only one = per row, and if the BeginTime, EndTime and StationName have the same writing in all files:



          read.table(
          file ="StationLog.txt",
          header =FALSE, # No column names
          sep ="=", # separator character
          strip.white =TRUE, # remove multiple white character
          row.names =1, # the first column contains the rownames
          stringsAsFactors=FALSE
          )[c("BeginTime", "EndTime", "StationName"), # extract the 3 infos based on their names corresponding to the rownames
          ,drop=FALSE] # keep the data.frame format


          And the result:



                                       V2
          BeginTime 2017-10-06.03:25:00
          EndTime 2017-10-06.03:55:00
          StationName STN67_P70





          share|improve this answer





















          • Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
            – Jim
            Nov 14 '18 at 10:38



















          0














          If you read the whole thing as a multiline string:



          data:



          txt_string <- "Version      = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"

          stationName<- regmatches(txt_string, gregexpr("StationName\s+=\s+\K\S+" ,txt_string, perl = T))
          beginTime <- regmatches(txt_string, gregexpr("BeginTime\s+=\s+\K\S+" ,txt_string, perl = T))
          endTime <- regmatches(txt_string, gregexpr("EndTime\s+=\s+\K\S+" ,txt_string, perl = T))

          do.call(cbind, c(stationName, beginTime, endTime))

          # [,1] [,2] [,3]
          #[1,] "STN67_P70" "2017-10-06.03:25:00" "2017-10-06.03:55:00"





          share|improve this answer





















          • Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
            – Jim
            Nov 14 '18 at 11:50












          • Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
            – Andre Elrico
            Nov 14 '18 at 11:56










          • Great stuff! Cheers for pointing me in the right direction
            – Jim
            Nov 14 '18 at 13:54



















          0














          Alternate method:



          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))


          base:



          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          )) -> station_info

          str(station_info, 1)
          ## List of 6
          ## $ Version : chr "2.0"
          ## $ StationName : chr "STN67_P70"
          ## $ BeginTime : chr "2017-10-06.03:25:00"
          ## $ EndTime : chr "2017-10-06.03:55:00"
          ## $ IgnoreNo : chr "5000"
          ## $ PumpedVolume: chr "0"


          tidyverse:



          library(tidyverse)

          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))

          str_split(station_info, pattern = "[[:space:]]*=[[:space:]]*") %>%
          map(~set_names(.x[2], .x[1])) %>%
          flatten() %>%
          str(1)


          Wrapping the base version (to avoid dependencies) into a function so you can re-use it for other stations:



          read_station_metadata <- function(path) {

          path <- path.expand(path)
          stopifnot(file.exists(path))

          station_info <- readLines(path, warn = FALSE)

          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          ))

          }





          share|improve this answer





















          • Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
            – Jim
            Nov 14 '18 at 15:30













          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%2f53297441%2fextracting-a-few-bits-of-data-from-txt-file%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Based on the read.table function, you can use the arguments to do what you want.



          The following proposal will work if you have only one = per row, and if the BeginTime, EndTime and StationName have the same writing in all files:



          read.table(
          file ="StationLog.txt",
          header =FALSE, # No column names
          sep ="=", # separator character
          strip.white =TRUE, # remove multiple white character
          row.names =1, # the first column contains the rownames
          stringsAsFactors=FALSE
          )[c("BeginTime", "EndTime", "StationName"), # extract the 3 infos based on their names corresponding to the rownames
          ,drop=FALSE] # keep the data.frame format


          And the result:



                                       V2
          BeginTime 2017-10-06.03:25:00
          EndTime 2017-10-06.03:55:00
          StationName STN67_P70





          share|improve this answer





















          • Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
            – Jim
            Nov 14 '18 at 10:38
















          2














          Based on the read.table function, you can use the arguments to do what you want.



          The following proposal will work if you have only one = per row, and if the BeginTime, EndTime and StationName have the same writing in all files:



          read.table(
          file ="StationLog.txt",
          header =FALSE, # No column names
          sep ="=", # separator character
          strip.white =TRUE, # remove multiple white character
          row.names =1, # the first column contains the rownames
          stringsAsFactors=FALSE
          )[c("BeginTime", "EndTime", "StationName"), # extract the 3 infos based on their names corresponding to the rownames
          ,drop=FALSE] # keep the data.frame format


          And the result:



                                       V2
          BeginTime 2017-10-06.03:25:00
          EndTime 2017-10-06.03:55:00
          StationName STN67_P70





          share|improve this answer





















          • Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
            – Jim
            Nov 14 '18 at 10:38














          2












          2








          2






          Based on the read.table function, you can use the arguments to do what you want.



          The following proposal will work if you have only one = per row, and if the BeginTime, EndTime and StationName have the same writing in all files:



          read.table(
          file ="StationLog.txt",
          header =FALSE, # No column names
          sep ="=", # separator character
          strip.white =TRUE, # remove multiple white character
          row.names =1, # the first column contains the rownames
          stringsAsFactors=FALSE
          )[c("BeginTime", "EndTime", "StationName"), # extract the 3 infos based on their names corresponding to the rownames
          ,drop=FALSE] # keep the data.frame format


          And the result:



                                       V2
          BeginTime 2017-10-06.03:25:00
          EndTime 2017-10-06.03:55:00
          StationName STN67_P70





          share|improve this answer












          Based on the read.table function, you can use the arguments to do what you want.



          The following proposal will work if you have only one = per row, and if the BeginTime, EndTime and StationName have the same writing in all files:



          read.table(
          file ="StationLog.txt",
          header =FALSE, # No column names
          sep ="=", # separator character
          strip.white =TRUE, # remove multiple white character
          row.names =1, # the first column contains the rownames
          stringsAsFactors=FALSE
          )[c("BeginTime", "EndTime", "StationName"), # extract the 3 infos based on their names corresponding to the rownames
          ,drop=FALSE] # keep the data.frame format


          And the result:



                                       V2
          BeginTime 2017-10-06.03:25:00
          EndTime 2017-10-06.03:55:00
          StationName STN67_P70






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 10:34









          Bastien

          1363




          1363












          • Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
            – Jim
            Nov 14 '18 at 10:38


















          • Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
            – Jim
            Nov 14 '18 at 10:38
















          Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
          – Jim
          Nov 14 '18 at 10:38




          Great, that's worked a treat, I can then extract the bits needed from the df. Cheers your help!
          – Jim
          Nov 14 '18 at 10:38













          0














          If you read the whole thing as a multiline string:



          data:



          txt_string <- "Version      = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"

          stationName<- regmatches(txt_string, gregexpr("StationName\s+=\s+\K\S+" ,txt_string, perl = T))
          beginTime <- regmatches(txt_string, gregexpr("BeginTime\s+=\s+\K\S+" ,txt_string, perl = T))
          endTime <- regmatches(txt_string, gregexpr("EndTime\s+=\s+\K\S+" ,txt_string, perl = T))

          do.call(cbind, c(stationName, beginTime, endTime))

          # [,1] [,2] [,3]
          #[1,] "STN67_P70" "2017-10-06.03:25:00" "2017-10-06.03:55:00"





          share|improve this answer





















          • Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
            – Jim
            Nov 14 '18 at 11:50












          • Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
            – Andre Elrico
            Nov 14 '18 at 11:56










          • Great stuff! Cheers for pointing me in the right direction
            – Jim
            Nov 14 '18 at 13:54
















          0














          If you read the whole thing as a multiline string:



          data:



          txt_string <- "Version      = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"

          stationName<- regmatches(txt_string, gregexpr("StationName\s+=\s+\K\S+" ,txt_string, perl = T))
          beginTime <- regmatches(txt_string, gregexpr("BeginTime\s+=\s+\K\S+" ,txt_string, perl = T))
          endTime <- regmatches(txt_string, gregexpr("EndTime\s+=\s+\K\S+" ,txt_string, perl = T))

          do.call(cbind, c(stationName, beginTime, endTime))

          # [,1] [,2] [,3]
          #[1,] "STN67_P70" "2017-10-06.03:25:00" "2017-10-06.03:55:00"





          share|improve this answer





















          • Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
            – Jim
            Nov 14 '18 at 11:50












          • Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
            – Andre Elrico
            Nov 14 '18 at 11:56










          • Great stuff! Cheers for pointing me in the right direction
            – Jim
            Nov 14 '18 at 13:54














          0












          0








          0






          If you read the whole thing as a multiline string:



          data:



          txt_string <- "Version      = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"

          stationName<- regmatches(txt_string, gregexpr("StationName\s+=\s+\K\S+" ,txt_string, perl = T))
          beginTime <- regmatches(txt_string, gregexpr("BeginTime\s+=\s+\K\S+" ,txt_string, perl = T))
          endTime <- regmatches(txt_string, gregexpr("EndTime\s+=\s+\K\S+" ,txt_string, perl = T))

          do.call(cbind, c(stationName, beginTime, endTime))

          # [,1] [,2] [,3]
          #[1,] "STN67_P70" "2017-10-06.03:25:00" "2017-10-06.03:55:00"





          share|improve this answer












          If you read the whole thing as a multiline string:



          data:



          txt_string <- "Version      = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"

          stationName<- regmatches(txt_string, gregexpr("StationName\s+=\s+\K\S+" ,txt_string, perl = T))
          beginTime <- regmatches(txt_string, gregexpr("BeginTime\s+=\s+\K\S+" ,txt_string, perl = T))
          endTime <- regmatches(txt_string, gregexpr("EndTime\s+=\s+\K\S+" ,txt_string, perl = T))

          do.call(cbind, c(stationName, beginTime, endTime))

          # [,1] [,2] [,3]
          #[1,] "STN67_P70" "2017-10-06.03:25:00" "2017-10-06.03:55:00"






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 11:17









          Andre Elrico

          5,63311027




          5,63311027












          • Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
            – Jim
            Nov 14 '18 at 11:50












          • Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
            – Andre Elrico
            Nov 14 '18 at 11:56










          • Great stuff! Cheers for pointing me in the right direction
            – Jim
            Nov 14 '18 at 13:54


















          • Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
            – Jim
            Nov 14 '18 at 11:50












          • Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
            – Andre Elrico
            Nov 14 '18 at 11:56










          • Great stuff! Cheers for pointing me in the right direction
            – Jim
            Nov 14 '18 at 13:54
















          Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
          – Jim
          Nov 14 '18 at 11:50






          Cheers for replying Andre That's the path I started down, but I can't get my head around the \s+= bit, what it means, I am sure its a method of selecting whats in there, but it puzzled me, if you wouldn't mind explaining for future reference?
          – Jim
          Nov 14 '18 at 11:50














          Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
          – Andre Elrico
          Nov 14 '18 at 11:56




          Hey, it's called regular expression. You can reference what the "bits" are doing on www.regex101.com for e.g.
          – Andre Elrico
          Nov 14 '18 at 11:56












          Great stuff! Cheers for pointing me in the right direction
          – Jim
          Nov 14 '18 at 13:54




          Great stuff! Cheers for pointing me in the right direction
          – Jim
          Nov 14 '18 at 13:54











          0














          Alternate method:



          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))


          base:



          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          )) -> station_info

          str(station_info, 1)
          ## List of 6
          ## $ Version : chr "2.0"
          ## $ StationName : chr "STN67_P70"
          ## $ BeginTime : chr "2017-10-06.03:25:00"
          ## $ EndTime : chr "2017-10-06.03:55:00"
          ## $ IgnoreNo : chr "5000"
          ## $ PumpedVolume: chr "0"


          tidyverse:



          library(tidyverse)

          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))

          str_split(station_info, pattern = "[[:space:]]*=[[:space:]]*") %>%
          map(~set_names(.x[2], .x[1])) %>%
          flatten() %>%
          str(1)


          Wrapping the base version (to avoid dependencies) into a function so you can re-use it for other stations:



          read_station_metadata <- function(path) {

          path <- path.expand(path)
          stopifnot(file.exists(path))

          station_info <- readLines(path, warn = FALSE)

          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          ))

          }





          share|improve this answer





















          • Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
            – Jim
            Nov 14 '18 at 15:30


















          0














          Alternate method:



          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))


          base:



          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          )) -> station_info

          str(station_info, 1)
          ## List of 6
          ## $ Version : chr "2.0"
          ## $ StationName : chr "STN67_P70"
          ## $ BeginTime : chr "2017-10-06.03:25:00"
          ## $ EndTime : chr "2017-10-06.03:55:00"
          ## $ IgnoreNo : chr "5000"
          ## $ PumpedVolume: chr "0"


          tidyverse:



          library(tidyverse)

          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))

          str_split(station_info, pattern = "[[:space:]]*=[[:space:]]*") %>%
          map(~set_names(.x[2], .x[1])) %>%
          flatten() %>%
          str(1)


          Wrapping the base version (to avoid dependencies) into a function so you can re-use it for other stations:



          read_station_metadata <- function(path) {

          path <- path.expand(path)
          stopifnot(file.exists(path))

          station_info <- readLines(path, warn = FALSE)

          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          ))

          }





          share|improve this answer





















          • Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
            – Jim
            Nov 14 '18 at 15:30
















          0












          0








          0






          Alternate method:



          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))


          base:



          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          )) -> station_info

          str(station_info, 1)
          ## List of 6
          ## $ Version : chr "2.0"
          ## $ StationName : chr "STN67_P70"
          ## $ BeginTime : chr "2017-10-06.03:25:00"
          ## $ EndTime : chr "2017-10-06.03:55:00"
          ## $ IgnoreNo : chr "5000"
          ## $ PumpedVolume: chr "0"


          tidyverse:



          library(tidyverse)

          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))

          str_split(station_info, pattern = "[[:space:]]*=[[:space:]]*") %>%
          map(~set_names(.x[2], .x[1])) %>%
          flatten() %>%
          str(1)


          Wrapping the base version (to avoid dependencies) into a function so you can re-use it for other stations:



          read_station_metadata <- function(path) {

          path <- path.expand(path)
          stopifnot(file.exists(path))

          station_info <- readLines(path, warn = FALSE)

          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          ))

          }





          share|improve this answer












          Alternate method:



          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))


          base:



          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          )) -> station_info

          str(station_info, 1)
          ## List of 6
          ## $ Version : chr "2.0"
          ## $ StationName : chr "STN67_P70"
          ## $ BeginTime : chr "2017-10-06.03:25:00"
          ## $ EndTime : chr "2017-10-06.03:55:00"
          ## $ IgnoreNo : chr "5000"
          ## $ PumpedVolume: chr "0"


          tidyverse:



          library(tidyverse)

          # use the filename vs this embedded example
          station_info <- readLines(textConnection("Version = 2.0
          StationName = STN67_P70
          BeginTime = 2017-10-06.03:25:00
          EndTime = 2017-10-06.03:55:00
          IgnoreNo = 5000
          PumpedVolume = 0"))

          str_split(station_info, pattern = "[[:space:]]*=[[:space:]]*") %>%
          map(~set_names(.x[2], .x[1])) %>%
          flatten() %>%
          str(1)


          Wrapping the base version (to avoid dependencies) into a function so you can re-use it for other stations:



          read_station_metadata <- function(path) {

          path <- path.expand(path)
          stopifnot(file.exists(path))

          station_info <- readLines(path, warn = FALSE)

          as.list(sapply(
          strsplit(station_info, split = "[[:space:]]*=[[:space:]]*"),
          function(x) setNames(x[2], x[1])
          ))

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 14:21









          hrbrmstr

          60.1k686148




          60.1k686148












          • Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
            – Jim
            Nov 14 '18 at 15:30




















          • Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
            – Jim
            Nov 14 '18 at 15:30


















          Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
          – Jim
          Nov 14 '18 at 15:30






          Cheers for your detailed reply, my aim was to put it into a function eventually so that's ideal! Thanks, although I have just opened up a new can of worms. Many thanks
          – Jim
          Nov 14 '18 at 15:30




















          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%2f53297441%2fextracting-a-few-bits-of-data-from-txt-file%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

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?