Yihui Xie
2009-Mar-23 08:59 UTC
[R] How to get commands history as a character vector instead of displaying them?
Hi Everyone, I want to get the commands history as a character vector instead of just displaying them, but the function history() just returns NULL. I checked the source code of 'history' and could not find a solution. Anybody has an idea? Thanks! P. S. My original problem is, when a user opens a graphics device like png() or pdf(), I want to know the file name used by this device. I thought history() would help, but it could not.> sessionInfo()R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=Chinese_People's Republic of China.936;LC_CTYPE=Chinese_People's Republic of China.936;LC_MONETARY=Chinese_People's Republic of China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936 attached base packages: [1] stats graphics grDevices utils datasets methods base Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China
Romain Francois
2009-Mar-23 09:10 UTC
[R] How to get commands history as a character vector instead of displaying them?
Yihui Xie wrote:> Hi Everyone, > > I want to get the commands history as a character vector instead of > just displaying them, but the function history() just returns NULL. I > checked the source code of 'history' and could not find a solution. > Anybody has an idea? Thanks! >history eventually calls file.show, which will use the pager option to determine how to show the file, so you can do something like that: history <- function( ... ){ old.op <- options( pager = function( files, header, title, delete.file ) readLines( files ) ); on.exit( options( old.op ) ) utils::history(...) } history( pattern = "png" ) I don't see a way to get device information other than the name of the device (with dev.cur) Romain> P. S. My original problem is, when a user opens a graphics device like > png() or pdf(), I want to know the file name used by this device. I > thought history() would help, but it could not. > > >> sessionInfo() >> > R version 2.8.1 (2008-12-22) > i386-pc-mingw32 > > locale: > LC_COLLATE=Chinese_People's Republic of > China.936;LC_CTYPE=Chinese_People's Republic of > China.936;LC_MONETARY=Chinese_People's Republic of > China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > Regards, > Yihui > -- > Yihui Xie <xieyihui at gmail.com> > Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 > Mobile: +86-15810805877 > Homepage: http://www.yihui.name > School of Statistics, Room 1037, Mingde Main Building, > Renmin University of China, Beijing, 100872, China > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr
Erich Neuwirth
2009-Mar-23 09:31 UTC
[R] How to get commands history as a character vector instead of displaying them?
Your original question probably is answered by dev.cur and dev.list Yihui Xie wrote:> Hi Everyone, > > I want to get the commands history as a character vector instead of > just displaying them, but the function history() just returns NULL. I > checked the source code of 'history' and could not find a solution. > Anybody has an idea? Thanks! > > P. S. My original problem is, when a user opens a graphics device like > png() or pdf(), I want to know the file name used by this device. I > thought history() would help, but it could not. > >> sessionInfo() > R version 2.8.1 (2008-12-22) > i386-pc-mingw32 > > locale: > LC_COLLATE=Chinese_People's Republic of > China.936;LC_CTYPE=Chinese_People's Republic of > China.936;LC_MONETARY=Chinese_People's Republic of > China.936;LC_NUMERIC=C;LC_TIME=Chinese_People's Republic of China.936 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > Regards, > Yihui > -- > Yihui Xie <xieyihui at gmail.com> > Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 > Mobile: +86-15810805877 > Homepage: http://www.yihui.name > School of Statistics, Room 1037, Mingde Main Building, > Renmin University of China, Beijing, 100872, China > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.0.238 / Virus Database: 270.11.24/2017 - Release Date: 03/22/09 17:51:00 >-- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459