How to create a function where if the R version is older than 3.5, it gives a warning?R and version control for the solo data analystdata.table vs dplyr: can one do something well the other can't or does poorly?warning messages when trying to run glmer in rHow should I deal with “package 'xxx' is not available (for R version x.y.z)” warning?no visible global function definition for ‘median’At least some columns satisfy a conditionpredict.gls fails when the package “MuMin” is installed in RProblems to configure Java for using in R version 3.5.0 and use rJava and coreNLP librariesError: package or namespace load failed, object … not foundSudden errors with as.data.frame with previously used code and objects

Why do textbooks often include the solutions to odd or even numbered problems but not both?

Why is prior to creation called holy?

Can humans ever directly see a few photons at a time? Can a human see a single photon?

How to make clear to people I don't want to answer their "Where are you from?" question?

Heavily limited premature compiler translates text into excecutable python code

What is the legal status of travelling with methadone in your carry-on?

How can I politely work my way around not liking coffee or beer when it comes to professional networking?

How is hair tissue mineral analysis performed?

What happened to Steve's Shield in Iron Man 2?

Count All Possible Unique Combinations of Letters in a Word

Is "Busen" just the area between the breasts?

What does the hyphen "-" mean in "tar xzf -"?

Why do even high-end cameras often still include normal (non-cross-type) AF sensors?

Why are < or > required to use /dev/tcp

Can White Castle?

How many children?

What could exist inside and between the walls of a Dyson Sphere?

When two first person POV characters meet

How large would a mega structure have to be to host 1 billion people indefinitely?

What size of powerbank will I need to power a phone and DSLR for 2 weeks?

Minor traveling without parents from USA to Sweden

Greeting with "Ho"

What is "industrial ethernet"?

How many people are necessary to maintain modern civilisation?



How to create a function where if the R version is older than 3.5, it gives a warning?


R and version control for the solo data analystdata.table vs dplyr: can one do something well the other can't or does poorly?warning messages when trying to run glmer in rHow should I deal with “package 'xxx' is not available (for R version x.y.z)” warning?no visible global function definition for ‘median’At least some columns satisfy a conditionpredict.gls fails when the package “MuMin” is installed in RProblems to configure Java for using in R version 3.5.0 and use rJava and coreNLP librariesError: package or namespace load failed, object … not foundSudden errors with as.data.frame with previously used code and objects






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I currently have the following code to see if the current R version is not equal to 3.5.0. However, I would like to change it so that if someone has a R version older than 3.5.0, it gives a warning to update R. Because 3.5.0 is not "less than" 3.4.0, etc, I am having issues creating a boolean command, since the computer doesnt recognize 3.4.0 as being "less than" 3.5.0. Is there a way to facilitate this?



if(strsplit(version[['version.string']], ' ')[[1]][3] != '3.5.0')
print("Warning: Update R")










share|improve this question

















  • 1





    You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

    – patL
    Mar 25 at 8:26







  • 3





    Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

    – Ronak Shah
    Mar 25 at 8:27







  • 1





    What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

    – Clemsang
    Mar 25 at 8:30












  • @Clemsang What does fixed=TRUE do?

    – user321627
    Mar 25 at 8:32






  • 1





    Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

    – Clemsang
    Mar 25 at 8:53

















2















I currently have the following code to see if the current R version is not equal to 3.5.0. However, I would like to change it so that if someone has a R version older than 3.5.0, it gives a warning to update R. Because 3.5.0 is not "less than" 3.4.0, etc, I am having issues creating a boolean command, since the computer doesnt recognize 3.4.0 as being "less than" 3.5.0. Is there a way to facilitate this?



if(strsplit(version[['version.string']], ' ')[[1]][3] != '3.5.0')
print("Warning: Update R")










share|improve this question

















  • 1





    You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

    – patL
    Mar 25 at 8:26







  • 3





    Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

    – Ronak Shah
    Mar 25 at 8:27







  • 1





    What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

    – Clemsang
    Mar 25 at 8:30












  • @Clemsang What does fixed=TRUE do?

    – user321627
    Mar 25 at 8:32






  • 1





    Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

    – Clemsang
    Mar 25 at 8:53













2












2








2








I currently have the following code to see if the current R version is not equal to 3.5.0. However, I would like to change it so that if someone has a R version older than 3.5.0, it gives a warning to update R. Because 3.5.0 is not "less than" 3.4.0, etc, I am having issues creating a boolean command, since the computer doesnt recognize 3.4.0 as being "less than" 3.5.0. Is there a way to facilitate this?



if(strsplit(version[['version.string']], ' ')[[1]][3] != '3.5.0')
print("Warning: Update R")










share|improve this question














I currently have the following code to see if the current R version is not equal to 3.5.0. However, I would like to change it so that if someone has a R version older than 3.5.0, it gives a warning to update R. Because 3.5.0 is not "less than" 3.4.0, etc, I am having issues creating a boolean command, since the computer doesnt recognize 3.4.0 as being "less than" 3.5.0. Is there a way to facilitate this?



if(strsplit(version[['version.string']], ' ')[[1]][3] != '3.5.0')
print("Warning: Update R")







r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 8:21









user321627user321627

487411




487411







  • 1





    You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

    – patL
    Mar 25 at 8:26







  • 3





    Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

    – Ronak Shah
    Mar 25 at 8:27







  • 1





    What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

    – Clemsang
    Mar 25 at 8:30












  • @Clemsang What does fixed=TRUE do?

    – user321627
    Mar 25 at 8:32






  • 1





    Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

    – Clemsang
    Mar 25 at 8:53












  • 1





    You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

    – patL
    Mar 25 at 8:26







  • 3





    Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

    – Ronak Shah
    Mar 25 at 8:27







  • 1





    What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

    – Clemsang
    Mar 25 at 8:30












  • @Clemsang What does fixed=TRUE do?

    – user321627
    Mar 25 at 8:32






  • 1





    Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

    – Clemsang
    Mar 25 at 8:53







1




1





You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

– patL
Mar 25 at 8:26






You can either change your version string to a number or do something like: if(strsplit(version[['version.string']], ' ')[[1]][3] < '3.5.0') print("Warning: Update R")

– patL
Mar 25 at 8:26





3




3





Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

– Ronak Shah
Mar 25 at 8:27






Actually '3.4.0' < '3.5.0', '3.4.9' < '3.5.0' does return TRUE but I think you still need some stricter checks.

– Ronak Shah
Mar 25 at 8:27





1




1





What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

– Clemsang
Mar 25 at 8:30






What about remove the dots as.numeric(gsub(".", "", substring(version[['version.string']], 11, 15), fixed = TRUE)) < 350

– Clemsang
Mar 25 at 8:30














@Clemsang What does fixed=TRUE do?

– user321627
Mar 25 at 8:32





@Clemsang What does fixed=TRUE do?

– user321627
Mar 25 at 8:32




1




1





Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

– Clemsang
Mar 25 at 8:53





Take the dots as dots in regular expressions, otherwise it is evaluated as any character. Fixed allows to have dot as a dot.

– Clemsang
Mar 25 at 8:53












2 Answers
2






active

oldest

votes


















2














You can transform version number like 3.5.0 to 350 by removing dots. This way you can easily compare current and target version :



if(gsub(".", "", strsplit(version[['version.string']], ' ')[[1]][3], fixed = TRUE) < '350')
print("Warning: Update R")






share|improve this answer






























    2














    The C interface has a nice convienence function to do this. You can see how it's defined:



    #define R_VERSION 197890
    #define R_NICK "Eggshell Igloo"
    #define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))


    So you can do something like this:



    #include <Rversion.h>

    // [[Rcpp::export]]
    bool isVersionOutdated()
    #if R_VERSION < R_Version(3, 5, 1)
    return true;
    #else
    return false;
    #endif



    R side:



    library(Rcpp)
    sourceCpp("test.cpp")
    isVersionOutdated()
    [1] FALSE





    share|improve this answer

























      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%2f55333691%2fhow-to-create-a-function-where-if-the-r-version-is-older-than-3-5-it-gives-a-wa%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You can transform version number like 3.5.0 to 350 by removing dots. This way you can easily compare current and target version :



      if(gsub(".", "", strsplit(version[['version.string']], ' ')[[1]][3], fixed = TRUE) < '350')
      print("Warning: Update R")






      share|improve this answer



























        2














        You can transform version number like 3.5.0 to 350 by removing dots. This way you can easily compare current and target version :



        if(gsub(".", "", strsplit(version[['version.string']], ' ')[[1]][3], fixed = TRUE) < '350')
        print("Warning: Update R")






        share|improve this answer

























          2












          2








          2







          You can transform version number like 3.5.0 to 350 by removing dots. This way you can easily compare current and target version :



          if(gsub(".", "", strsplit(version[['version.string']], ' ')[[1]][3], fixed = TRUE) < '350')
          print("Warning: Update R")






          share|improve this answer













          You can transform version number like 3.5.0 to 350 by removing dots. This way you can easily compare current and target version :



          if(gsub(".", "", strsplit(version[['version.string']], ' ')[[1]][3], fixed = TRUE) < '350')
          print("Warning: Update R")







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 8:56









          ClemsangClemsang

          1,166816




          1,166816























              2














              The C interface has a nice convienence function to do this. You can see how it's defined:



              #define R_VERSION 197890
              #define R_NICK "Eggshell Igloo"
              #define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))


              So you can do something like this:



              #include <Rversion.h>

              // [[Rcpp::export]]
              bool isVersionOutdated()
              #if R_VERSION < R_Version(3, 5, 1)
              return true;
              #else
              return false;
              #endif



              R side:



              library(Rcpp)
              sourceCpp("test.cpp")
              isVersionOutdated()
              [1] FALSE





              share|improve this answer



























                2














                The C interface has a nice convienence function to do this. You can see how it's defined:



                #define R_VERSION 197890
                #define R_NICK "Eggshell Igloo"
                #define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))


                So you can do something like this:



                #include <Rversion.h>

                // [[Rcpp::export]]
                bool isVersionOutdated()
                #if R_VERSION < R_Version(3, 5, 1)
                return true;
                #else
                return false;
                #endif



                R side:



                library(Rcpp)
                sourceCpp("test.cpp")
                isVersionOutdated()
                [1] FALSE





                share|improve this answer

























                  2












                  2








                  2







                  The C interface has a nice convienence function to do this. You can see how it's defined:



                  #define R_VERSION 197890
                  #define R_NICK "Eggshell Igloo"
                  #define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))


                  So you can do something like this:



                  #include <Rversion.h>

                  // [[Rcpp::export]]
                  bool isVersionOutdated()
                  #if R_VERSION < R_Version(3, 5, 1)
                  return true;
                  #else
                  return false;
                  #endif



                  R side:



                  library(Rcpp)
                  sourceCpp("test.cpp")
                  isVersionOutdated()
                  [1] FALSE





                  share|improve this answer













                  The C interface has a nice convienence function to do this. You can see how it's defined:



                  #define R_VERSION 197890
                  #define R_NICK "Eggshell Igloo"
                  #define R_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))


                  So you can do something like this:



                  #include <Rversion.h>

                  // [[Rcpp::export]]
                  bool isVersionOutdated()
                  #if R_VERSION < R_Version(3, 5, 1)
                  return true;
                  #else
                  return false;
                  #endif



                  R side:



                  library(Rcpp)
                  sourceCpp("test.cpp")
                  isVersionOutdated()
                  [1] FALSE






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 9:02









                  thcthc

                  6,17711225




                  6,17711225



























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333691%2fhow-to-create-a-function-where-if-the-r-version-is-older-than-3-5-it-gives-a-wa%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

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해