R/HistMapR-internal.R

Defines functions .rgedit.lastline2clipboard

.adjustWidth <-
function (...) 
{
    options(width = Sys.getenv("COLUMNS"))
    TRUE
}
.adjustWidthCallBack <-
structure(1L, .Names = "1")
.Random.seed <-
c(403L, 10L, 136783878L, -250131568L, -1602300365L, 304334289L, 
316626816L, 1183025758L, -1806028375L, -1836375973L, -899549078L, 
199366924L, -2135870641L, 1217982469L, -966029636L, 1096042386L, 
1532998797L, -1479937337L, 660431790L, -292831736L, -1248202229L, 
-1604394263L, 1852149176L, 823192166L, -752118015L, -1986616941L, 
-1484686782L, 597495284L, -51300361L, 32746477L, -294435708L, 
-403907926L, 1670909973L, 905664687L, 1611658934L, -1197767456L, 
-1624586205L, -2099538111L, -604054992L, 119523406L, -1273087815L, 
-1623986997L, 817295738L, 1593044092L, -1236350785L, 1874886037L, 
-977322580L, 260904834L, -565510819L, -1223805865L, 1262048062L, 
2081913720L, -1063962533L, 881819577L, -9355768L, -91001674L, 
-422937615L, -1861466589L, -423430542L, 1458187460L, 661760647L, 
706912861L, 1454253140L, 1406545530L, 634260933L, 736407327L, 
-1850238298L, -1694753744L, 55475923L, 26729713L, 1655126048L, 
-304111938L, 824015561L, -2029907845L, 1745997386L, -1584334164L, 
1594830255L, -1496965787L, -1670001892L, 2111975282L, -668875795L, 
1074332711L, 1039438L, 994156712L, 1098124971L, 1935698889L, 
-1339029544L, -547729786L, 2103547745L, 1964608243L, -1888086686L, 
33874900L, -1431632169L, 625110221L, 976186468L, -521330102L, 
2075568053L, 447970063L, -760920042L, 786109120L, -2139282301L, 
657608865L, 1553241744L, 1832912238L, -884739303L, -238389333L, 
449844634L, -2119863972L, 1267828831L, 241305653L, 1099779020L, 
-176849118L, -8461955L, 2049280631L, 342152094L, -963419560L, 
65457083L, 601062745L, -423790872L, -1488894186L, 1659308177L, 
-1291647677L, -529285038L, 86909668L, -913279705L, -1180840579L, 
1664337012L, -4518310L, 533887653L, 1368309951L, 1049314118L, 
1722716624L, 218117107L, 570493713L, -910951616L, -748027106L, 
811813865L, 749601051L, 1275706154L, 1619360844L, -557501425L, 
2003648325L, 265132284L, 1652729682L, -567121715L, -272287609L, 
-373118098L, -1581007544L, -1586976437L, 1729100969L, 689708536L, 
2140030246L, -906283455L, 1445281747L, 610932098L, -1025672780L, 
1727431991L, -939536339L, -1463345852L, 339712618L, 1058043093L, 
-600341905L, 1058842486L, 2016200864L, 344809827L, 1762931201L, 
783303024L, -1018633970L, -225799303L, 251124491L, -803322822L, 
1345151804L, 1474705535L, 830249941L, -409684500L, -76761278L, 
-1141770083L, 491258135L, -7300994L, -1362956232L, -1960696037L, 
-1735482247L, -1402753848L, -216564490L, 193969457L, 1194745187L, 
1915977522L, -945604476L, -1026792249L, -613611619L, 172430100L, 
-1625062982L, -1000335355L, -549769761L, -1269653402L, 111022064L, 
1782442259L, 1711003313L, 2073338208L, -189966594L, 1447211657L, 
-1047458373L, -261449846L, 1403625068L, -478478353L, 675682341L, 
-1543472932L, 266313394L, 225169837L, -1762126489L, 46588558L, 
-485250200L, 906417003L, -1936380663L, 72557464L, -341298490L, 
-2045216735L, -1859957581L, 786222626L, -1725902828L, -1869327209L, 
1132068493L, 1007562660L, -1882934902L, 320531957L, -1290928049L, 
780891990L, -336335360L, -1519444157L, -159446528L, -725391300L, 
220867152L, 950550690L, -417049784L, 367026700L, 1330492124L, 
-288511918L, 1912941696L, 1660579668L, 1162395624L, 555809530L, 
344850256L, 1852281900L, -2086129292L, -1543571822L, -775021984L, 
-1131620212L, 439650656L, -1718736670L, -2028837720L, 1447632588L, 
54307324L, -16141390L, 501742576L, 1253091780L, 183201112L, 328096122L, 
1371019696L, -871816772L, -1433366956L, 886749634L, -83473632L, 
-1923720260L, 799928400L, -665443358L, 683575144L, 2061655884L, 
917081852L, -1361359118L, -1073640192L, 1716724852L, 1706487304L, 
2138324410L, 1535067600L, 2031185900L, 580537236L, -76762926L, 
-502121376L, 42104140L, 617909024L, 2026158722L, 1351770600L, 
-1614339092L, 1143461436L, -418840974L, 146731888L, 493178148L, 
-707732936L, 1010225562L, -1548859952L, 349889980L, -342325612L, 
1357824642L, 1949865408L, -942248132L, -274238832L, 425961250L, 
-1706273272L, -115604724L, -2058576996L, -1405697006L, -308735104L, 
-1528427756L, -1707444952L, -1937895366L, 504558544L, 1471044204L, 
2002992180L, 1317148818L, -1953021600L, 1727671628L, -80376352L, 
531706786L, 1957989288L, -632599412L, -911604804L, 117701746L, 
2076760048L, 321918020L, 1546598488L, 542826554L, -1007701904L, 
-96610756L, -1467099372L, 1443195586L, 892162784L, 286182524L, 
3898576L, 1236896674L, -1094930904L, 622983436L, 1054955452L, 
-1971492558L, -1089281856L, -1197243852L, -355726648L, 1819114170L, 
-1724185456L, -1390758164L, 786718292L, 765019794L, -1475291360L, 
-1997174836L, -45342496L, 1962868418L, 1560904744L, -981644372L, 
-1197860164L, -764458510L, 1765021232L, 1000621988L, 296718776L, 
-448007334L, -1931103088L, -1075479684L, -899254508L, 398331202L, 
-637255936L, 286438332L, -2049208496L, 1746852130L, 467771976L, 
-1930514420L, -1006193572L, 1347781074L, -1900519936L, 305770836L, 
1132458216L, 1886081274L, -178911536L, 1202770220L, 1221693684L, 
-1798918766L, 1968138592L, -2076137460L, 1060135648L, 170113634L, 
-2101128536L, 1359948364L, 1867194236L, 1453524274L, -1975962000L, 
-1893280956L, -1697110056L, -2023336070L, 1072195120L, 1927206844L, 
-953289132L, -508485566L, -617795424L, 753268412L, -688916016L, 
694702946L, -497552664L, -1247862580L, 182264316L, 1081745906L, 
293563008L, 1479089652L, -364960120L, 1049993018L, 693375824L, 
-1314075540L, 1063825812L, 1277391954L, 1004421600L, -2093028148L, 
1868891296L, -300481150L, 1565550824L, -2103814420L, -774961860L, 
381820018L, -473089936L, -396890076L, 1175460920L, -490508518L, 
-416273200L, -1935212740L, 2058467220L, -1845976190L, 1651157440L, 
444022332L, -2094701168L, 697720354L, -1364933368L, -1247117684L, 
-1754190052L, -731152238L, 1989491072L, 400791060L, 1079815976L, 
826616378L, 1580301776L, 379210092L, -190757964L, -319260654L, 
-23738912L, -877766708L, -1382694688L, -304826334L, -702992088L, 
-1566372340L, 1406084924L, -815721486L, -823530768L, -1816039868L, 
572756568L, 874061626L, -1060858384L, -290212164L, -722020076L, 
-1459776830L, -460766112L, -403434628L, 2074535888L, -1195356733L, 
1080002244L, 1268043122L, -1642258361L, -1712757743L, -1584069226L, 
666163444L, 327357061L, 1453710287L, -1019817272L, 866530150L, 
-1633711725L, 222528245L, -753935662L, -1893956320L, 885452041L, 
-784451013L, 936243084L, 848506394L, 2042287759L, -185667111L, 
-2062891410L, 2014455292L, 1801658221L, 1394280727L, -663542560L, 
1258982078L, -401241973L, 1553643277L, 1667438394L, -25088136L, 
-173325023L, -1254369837L, 1929606388L, 1225198978L, 1660712983L, 
305102561L, -369940442L, 1540828452L, 2000737749L, -1693460097L, 
-2045212648L, 978351926L, -53325373L, 10412037L, -1897184350L, 
609619856L, 2003741497L, -312246293L, -1171857188L, 2128273674L, 
-489345025L, 2000454217L, 1257498590L, 392226700L, 1094252381L, 
863006567L, -1172646768L, -1373439314L, -937437349L, -1275943107L, 
-1190750806L, -144008632L, -1613612431L, 59513827L, 170804964L, 
-87024110L, -1379046937L, -1701280335L, 1827816438L, -100061676L, 
531378469L, -1492231633L, 243032040L, -60585786L, 1351994739L, 
794236373L, -385181262L, 244553600L, -575730839L, -418922533L, 
-1271601364L, -2015491782L, -2054424593L, 659669625L, 510608654L, 
-767709988L, -441187507L, 1692994231L, -912693184L, 821856542L, 
-1348873237L, -1706975379L, 885544410L, -333928552L, -35396095L, 
685590451L, -1213253932L, 501960674L, -1254772105L, -241341503L, 
-1490544314L, 1062979716L, 684363317L, -661309921L, 86266232L, 
-1732726698L, -84624157L, -2009318747L, 1261995842L, 1374270768L, 
-353606311L, -167016757L, 17415996L, -1146693782L, -1649248865L, 
1143098409L, 894291646L, -367648852L, 806757629L, 1769381959L, 
-309600464L, 371001422L, 697271419L, -1345902627L, 295310858L, 
-1803424984L, -1877633647L, -474477693L, -151408508L, -1514479950L, 
-1041276409L, 853897809L, 1919085014L, -900737868L, -2100604731L, 
-1030512113L, -1138386296L, 18694054L, -711518381L, -848844619L, 
-357521902L, 1841402848L, 1287677513L, 982733947L, 1121604940L, 
2089328858L, -870223665L, -590541671L, -495095634L, 1138437564L, 
-77081043L, -2042359337L, 349001760L, -1889337986L, 537879371L, 
321808717L, -1825134726L, -218535496L, 2146868065L, -221652205L, 
-501837004L, -2059849406L, -1549736617L, -94502751L, 521808230L, 
1048632164L, -152964459L, 699454399L, 473598455L)
.rgedit.lastline2clipboard <-
function( clipboard.command = "xclip" ) 
{
  # The possible clipboard commands:
  clipboard.commands <- c( "xclip", "xsel", "pbcopy" );
  # The correct command line depending on the option used:
  pipe.commands <- c( "xclip -i -selection clipboard", "xsel --clipboard", "pbcopy" );
  names(pipe.commands) <- clipboard.commands;

  # Try to detect which clipboard commands are installed in the system:
  available.clipboard.commands <- c( FALSE, FALSE, FALSE ); names(available.clipboard.commands) <- clipboard.commands;
  for( i in 1:length(available.clipboard.commands) )
  {
    available.clipboard.commands[i] <- length(system( paste( "command -v ", names(available.clipboard.commands)[i], sep=""), intern=TRUE )) > 0;
  } 
  if( sum(available.clipboard.commands) == 0 )
  {
    stop( "No cpliboard manipulation programs installed on your machine! Please install xclip or xsel (on *nix) and pbcopy (on MacOSX)!\n" );
  }

  # Try to satisfly the user's preference:
  if( sum(clipboard.command == names(pipe.commands)) == 0 )
  {
    # Unknown clipboard command: print a warning and try your best:
    cat( "Warning: unknown option ", clipboard.command );
    clipboard.command = (names(available.clipboard.commands)[available.clipboard.commands])[1];
    cat( " -- using ", clipboard.command, " instead...\n" );
  }
  else if( !available.clipboard.commands[clipboard.command] )
  {
    # Preferred command not installed: print a warning and try your best:
    cat( "Warning: requested command ", clipboard.command );
    clipboard.command = (names(available.clipboard.commands)[available.clipboard.commands])[1];
    cat( " -- using ", clipboard.command, " instead...\n" );
  }

  # Save whole shitory to temporaty file:
  hist.file <- tempfile( "Rhistory" );
  savehistory( hist.file );
  full.hist <- readLines( hist.file );
  unlink( hist.file );

  # Read the last line before this one:
  last.line <- full.hist[ length(full.hist)-1 ];
 
  # And copy it to the clipboard: 
  clipboard.pipe <- pipe( pipe.commands[clipboard.command], "w" );
  cat( paste(last.line,"\n",sep=""), file=clipboard.pipe );
  close( clipboard.pipe );
  
  # Restore the history without the last command:
  hist.file <- tempfile( "Rhistory" );
  writeLines( full.hist[ -length(full.hist) ], hist.file );
  loadhistory( hist.file );
  unlink( hist.file );
}
AGAuffret/HistMapR documentation built on July 20, 2023, 2:43 a.m.