Re: [R] installation: while running make, unable to run pdflatex on 'NEWS.tex'
В Fri, 1 Mar 2024 10:46:53 -0500 Benjamin Tyner пишет: > my platform info: > > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Ubuntu 22.04.4 LTS Quick things first: have you installed all the build-dependencies? apt build-dep r-base (maybe with --install-suggests? haven't tried that in a while) should do that. In particular, the build dependencies include texlive-fonts-extra and texlive-latex-extra. That's a lot of packages, but some of them are required to compile LaTeX documents produced by R. > you should 'make docs' now ... > make[1]: Entering directory '/home/btyner/R-4.3.3/doc' > creating doc/NEWS > creating doc/NEWS.pdf > Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = > quiet, : > unable to run pdflatex on 'NEWS.tex' > LaTeX errors: > ! LaTeX Error: File `pdftexcmds.sty' not found. Can you compile a minimal LaTeX document? Something like: \documentclass{article} \begin{document} \[ \mathbf{y} = \mathbf{X} \beta \] \end{document} Does tools::texi2pdf('THISFILE.tex') fail with a similar error message? -- Best regards, Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] installation: while running make, unable to run pdflatex on 'NEWS.tex'
This really is all LaTeX errors, not R errors. Both examples complain that pdftexcmds.sty is not installed. Most "sty" files are in LaTeX packages. Each LaTeX distribution has its own way to install packages ... but the difficulty is usually on the same order of difficulty as installing R packages from CRAN... that is, pretty easy. But you need to read about _your_ TeX system for details. I use Google to figure out which package has the given file in it... it is usually the same as whatever comes before ".sty", but not always. On March 1, 2024 7:46:53 AM PST, Benjamin Tyner wrote: > >A kind member of R-core suggested this is due to a misconfiguration on my >system, and to post it to the mailing list for troubleshooting. > >When trying to build R version 4.3.3, in at least two places during the >process it gives LaTeX errors of the form: > >(example 1) > > you should 'make docs' now ... > make[1]: Entering directory '/home/btyner/R-4.3.3/doc' > creating doc/NEWS > creating doc/NEWS.pdf > Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = > quiet, : > unable to run pdflatex on 'NEWS.tex' > LaTeX errors: > ! LaTeX Error: File `pdftexcmds.sty' not found. > > Type X to quit or to proceed, > or enter new name. (Default extension: sty) > > ! Emergency stop. > > > l.108 RequirePackage{pdftexcmds}[2018/09/10] > ^^M > ! ==> Fatal error occurred, no output PDF file produced! > Calls: -> texi2pdf -> texi2dvi > Execution halted > make[1]: /*/ [Makefile:74: NEWS.pdf] Error 1 > make[1]: Leaving directory '/home/btyner/R-4.3.3/doc' > make: [Makefile:73: docs] Error 2 (ignored) > >(example 2) > > make[1]: Entering directory '/home/btyner/R-4.3.3/src/library' > building/updating vignettes for package 'grid' ... > building/updating vignettes for package 'parallel' ... > building/updating vignettes for package 'utils' ... > building/updating vignettes for package 'stats' ... > processing 'reshape.Rnw' > Error: compiling TeX file 'reshape.tex' failed with message: > unable to run pdflatex on 'reshape.tex' > LaTeX errors: > ! LaTeX Error: File `pdftexcmds.sty' not found. > > Type X to quit or to proceed, > or enter new name. (Default extension: sty) > > ! Emergency stop. > > > l.108 RequirePackage{pdftexcmds}[2018/09/10] > ^^M > ! ==> Fatal error occurred, no output PDF file produced! > Execution halted > make[1]: ** [Makefile:103: vignettes] Error 1 > make[1]: Leaving directory '/home/btyner/R-4.3.3/src/library' > make: ** [Makefile:81: vignettes] Error 2 > >here is my |pdflatex --version| info: > > pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) > kpathsea version 6.3.4/dev > Compiled with libpng 1.6.37; using libpng 1.6.37 > Compiled with zlib 1.2.11; using zlib 1.2.11 > Compiled with xpdf version 4.03 > >my platform info: > > Platform: x86_64-pc-linux-gnu (64-bit) > Running under: Ubuntu 22.04.4 LTS > >I installed from this file with corresponding md5sum > > R-4.3.3.tar.xz 5602f5996107c346dba12a16e866d2e2 > >The specific commands I ran which led to the error were: > > wget https://cran.r-project.org/src/base/R-4/R-4.3.3.tar.xz > mkdir R433 > tar xJf R-4.3.3.tar.xz > cd R-4.3.3 > ./configure --prefix=/home/btyner/R433 > make > >Happy to provide any additional information needed. > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] dput(..., file = stderr())
В Fri, 1 Mar 2024 10:54:08 -0500 Benjamin Tyner пишет: > > dput(letters, file = stderr()) > c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", > "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", > "z") > Warning message: > In dput(letters, file = stderr()) : wrote too few characters Sounds like a bug. This is where the warning is produced: int res = Rconn_printf(con, "%s\n", CHAR(STRING_ELT(tval, i))); if(!havewarned && res < strlen(CHAR(STRING_ELT(tval, i))) + 1) { warning(_("wrote too few characters")); havewarned = TRUE; } At this point, `res` is 0, and CHAR(STRING_ELT(tval, i)) is what you'd expect: (gdb) x /s (void*)(STRING_ELT(tval, i))+48 0x561bf0a8: "c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", " `res` is 0 because that's what (con->vfprintf)(...) returns: 2813static int stderr_vfprintf(Rconnection con, const char *format, va_list ap) 2814{ 2815REvprintf(format, ap); 2816return 0; 2817} Why doesn't it warn for stdout()? Doesn't stdout_vfprintf(...) behave the same? That's because stdout() (connection #1) is special for dput(), and instead of going through the connection system, it goes straight for Rprintf(): 426 else { // ifile == 1 : "Stdout" 427 for (int i = 0; i < LENGTH(tval); i++) 428 Rprintf("%s\n", CHAR(STRING_ELT(tval, i))); 429 } Not sure what the right fix is. There may be code depending on (con->vfprintf)(...) returning 0. -- Best regards, Ivan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] [External] dput(..., file = stderr())
I see the same thing in a fresh R session > dput(letters, file = stderr()) c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") Warning message: In dput(letters, file = stderr()) : wrote too few characters > dput(letters, file = stdout()) c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") > version _ platform aarch64-apple-darwin20 arch aarch64 os darwin20 system aarch64, darwin20 status Patched major 4 minor 3.2 year 2024 month 01 day23 svn rev85822 language R version.string R version 4.3.2 Patched (2024-01-23 r85822) nickname Eye Holes > > On Mar 1, 2024, at 10:54, Benjamin Tyner wrote: > > dput(letters, file = stderr()) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] gsub issue with consecutive pattern finds
Oh, wait a second. I misread your original post. Please ignore my truly incorrect suggestion. -- Bert On Fri, Mar 1, 2024 at 7:57 AM Bert Gunter wrote: > > Here's another *incorrect* way to do it -- incorrect because it will > not always work, unlike Iris's correct solution. But it does not > require PERL type matching. The idea: separate the two vowels in the > regex by a character that you know cannot appear (if there is such) > and match it optionally, e.g. with '*" repetition specifier. I used > "?" for the optional character below (which must be escaped). > > >gsub("([aeiouAEIOU])\\?*([aeiouAEIOU])", "\\1_\\2", "aerioue") > [1] "a_eri_ou_e" > > Cheers, > Bert > > > On Fri, Mar 1, 2024 at 3:59 AM Iago Giné Vázquez wrote: > > > > Hi Iris, > > > > Thank you. Further, very nice solution. > > > > Best, > > > > Iago > > > > On 01/03/2024 12:49, Iris Simmons wrote: > > > Hi Iago, > > > > > > > > > This is not a bug. It is expected. Patterns may not overlap. However, > > > there > > > is a way to get the result you want using perl: > > > > > > ```R > > > gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) > > > ``` > > > > > > The specific change I made is called a positive lookahead, you can read > > > more about it here: > > > > > > https://www.regular-expressions.info/lookaround.html > > > > > > It's a way to check for a piece of text without consuming it in the match. > > > > > > Also, since you don't care about character case, it might be more legible > > > to add ignore.case = TRUE and remove the upper case characters: > > > > > > ```R > > > gsub("([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE, ignore.case = > > > TRUE) > > > > > > ## or > > > > > > gsub("(?i)([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE) > > > ``` > > > > > > I hope this helps! > > > > > > > > > On Fri, Mar 1, 2024, 06:37 Iago Giné Vázquez wrote: > > > > > >> Hi all, > > >> > > >> I tested next command: > > >> > > >> gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") > > >> > > >> with the following output: > > >> > > >> [1] "a_eri_ou_e" > > >> > > >> So, there are two consecutive vowels where an underscore is not added. > > >> > > >> May it be a bug? Is it expected (bug or not)? Is there any chance to get > > >> what I want (an underscore between each pair of consecutive vowels)? > > >> > > >> > > >> Thank you! > > >> > > >> Best regards, > > >> > > >> Iago > > >> > > >> [[alternative HTML version deleted]] > > >> > > >> __ > > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > >> 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. > > >> > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] gsub issue with consecutive pattern finds
Here's another *incorrect* way to do it -- incorrect because it will not always work, unlike Iris's correct solution. But it does not require PERL type matching. The idea: separate the two vowels in the regex by a character that you know cannot appear (if there is such) and match it optionally, e.g. with '*" repetition specifier. I used "?" for the optional character below (which must be escaped). >gsub("([aeiouAEIOU])\\?*([aeiouAEIOU])", "\\1_\\2", "aerioue") [1] "a_eri_ou_e" Cheers, Bert On Fri, Mar 1, 2024 at 3:59 AM Iago Giné Vázquez wrote: > > Hi Iris, > > Thank you. Further, very nice solution. > > Best, > > Iago > > On 01/03/2024 12:49, Iris Simmons wrote: > > Hi Iago, > > > > > > This is not a bug. It is expected. Patterns may not overlap. However, there > > is a way to get the result you want using perl: > > > > ```R > > gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) > > ``` > > > > The specific change I made is called a positive lookahead, you can read > > more about it here: > > > > https://www.regular-expressions.info/lookaround.html > > > > It's a way to check for a piece of text without consuming it in the match. > > > > Also, since you don't care about character case, it might be more legible > > to add ignore.case = TRUE and remove the upper case characters: > > > > ```R > > gsub("([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE, ignore.case = > > TRUE) > > > > ## or > > > > gsub("(?i)([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE) > > ``` > > > > I hope this helps! > > > > > > On Fri, Mar 1, 2024, 06:37 Iago Giné Vázquez wrote: > > > >> Hi all, > >> > >> I tested next command: > >> > >> gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") > >> > >> with the following output: > >> > >> [1] "a_eri_ou_e" > >> > >> So, there are two consecutive vowels where an underscore is not added. > >> > >> May it be a bug? Is it expected (bug or not)? Is there any chance to get > >> what I want (an underscore between each pair of consecutive vowels)? > >> > >> > >> Thank you! > >> > >> Best regards, > >> > >> Iago > >> > >> [[alternative HTML version deleted]] > >> > >> __ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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. > >> > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] dput(..., file = stderr())
Curious to know if this warning is expected behavior, and if so, what is the recommended way instead: > dput(letters, file = stderr()) c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") Warning message: In dput(letters, file = stderr()) : wrote too few characters (I ask because it doesn't happen when using file = stdout()) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] installation: while running make, unable to run pdflatex on 'NEWS.tex'
A kind member of R-core suggested this is due to a misconfiguration on my system, and to post it to the mailing list for troubleshooting. When trying to build R version 4.3.3, in at least two places during the process it gives LaTeX errors of the form: (example 1) you should 'make docs' now ... make[1]: Entering directory '/home/btyner/R-4.3.3/doc' creating doc/NEWS creating doc/NEWS.pdf Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : unable to run pdflatex on 'NEWS.tex' LaTeX errors: ! LaTeX Error: File `pdftexcmds.sty' not found. Type X to quit or to proceed, or enter new name. (Default extension: sty) ! Emergency stop. l.108 RequirePackage{pdftexcmds}[2018/09/10] ^^M ! ==> Fatal error occurred, no output PDF file produced! Calls: -> texi2pdf -> texi2dvi Execution halted make[1]: /*/ [Makefile:74: NEWS.pdf] Error 1 make[1]: Leaving directory '/home/btyner/R-4.3.3/doc' make: [Makefile:73: docs] Error 2 (ignored) (example 2) make[1]: Entering directory '/home/btyner/R-4.3.3/src/library' building/updating vignettes for package 'grid' ... building/updating vignettes for package 'parallel' ... building/updating vignettes for package 'utils' ... building/updating vignettes for package 'stats' ... processing 'reshape.Rnw' Error: compiling TeX file 'reshape.tex' failed with message: unable to run pdflatex on 'reshape.tex' LaTeX errors: ! LaTeX Error: File `pdftexcmds.sty' not found. Type X to quit or to proceed, or enter new name. (Default extension: sty) ! Emergency stop. l.108 RequirePackage{pdftexcmds}[2018/09/10] ^^M ! ==> Fatal error occurred, no output PDF file produced! Execution halted make[1]: ** [Makefile:103: vignettes] Error 1 make[1]: Leaving directory '/home/btyner/R-4.3.3/src/library' make: ** [Makefile:81: vignettes] Error 2 here is my |pdflatex --version| info: pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) kpathsea version 6.3.4/dev Compiled with libpng 1.6.37; using libpng 1.6.37 Compiled with zlib 1.2.11; using zlib 1.2.11 Compiled with xpdf version 4.03 my platform info: Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.4 LTS I installed from this file with corresponding md5sum R-4.3.3.tar.xz 5602f5996107c346dba12a16e866d2e2 The specific commands I ran which led to the error were: wget https://cran.r-project.org/src/base/R-4/R-4.3.3.tar.xz mkdir R433 tar xJf R-4.3.3.tar.xz cd R-4.3.3 ./configure --prefix=/home/btyner/R433 make Happy to provide any additional information needed. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] Interactions in regression
Hi Rolf, No it is not. I don't know to which question did you want to respond ? I desribed everything in my first email and attached links from SO with pictures included, which are quite understandable. Cheers, Jacek śr., 28 lut 2024 o 19:42 Jacek Kownacki napisał(a): > Hi Rolf, > No it is not. > I don't know to which question did you want to respond ? > I desribed everything in my first email and attached links from SO with > pictures included, which are quite understandable. > > Cheers, > Jacek > > wt., 27 lut 2024 o 02:29 Rolf Turner napisał(a): > >> >> I have no real idea what you are trying to do, but if a table is >> what you want, you can probably get it using the table() function. >> Or, more likely, the xtabs() function. >> >> Using your example from an earlier post (adjusted to make it >> comprehensible to the human mind): >> >> set.seed(1000) >> time <- factor(rep(c("Pre","Post"),each=200)) >> treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2)) >> mu<- rep(rep(1:2,each=100),2) >> response <- rnorm(400,mean=mu) >> xmpldata <- data.frame(time=time,treatment=treatment,response) >> mod <- lm(response~time*treatment,data=xmpldata) >> yhat <- fitted(mod) >> xtb <- with(xmpldata,xtabs(yhat ~ time+treatment)) >> >> print(xtb) >> >> > treatment >> > time Control Treatment >> > Post 94.10501 201.99112 >> > Pre 101.63792 210.04248 >> >> Is that (something like) what you want? >> >> cheers, >> >> Rolf Turner >> >> P.S. You said: "I usually use GUI software". Now *there* lies your >> problem. A GUI is a black box that removes all control over what is >> going on, from your hands. >> >> R. T. >> >> >> >> >> -- >> Honorary Research Fellow >> Department of Statistics >> University of Auckland >> Stats. Dep't. (secretaries) phone: >> +64-9-373-7599 ext. 89622 >> Home phone: +64-9-480-4619 >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] Interactions in regression
Hi Rolf, No it is not. I don't know to which question did you want to respond ? I desribed everything in my first email and attached links from SO with pictures included, which are quite understandable. Cheers, Jacek wt., 27 lut 2024 o 02:29 Rolf Turner napisał(a): > > I have no real idea what you are trying to do, but if a table is > what you want, you can probably get it using the table() function. > Or, more likely, the xtabs() function. > > Using your example from an earlier post (adjusted to make it > comprehensible to the human mind): > > set.seed(1000) > time <- factor(rep(c("Pre","Post"),each=200)) > treatment <- factor(rep(rep(c("Control","Treatment"),each=100),2)) > mu<- rep(rep(1:2,each=100),2) > response <- rnorm(400,mean=mu) > xmpldata <- data.frame(time=time,treatment=treatment,response) > mod <- lm(response~time*treatment,data=xmpldata) > yhat <- fitted(mod) > xtb <- with(xmpldata,xtabs(yhat ~ time+treatment)) > > print(xtb) > > > treatment > > time Control Treatment > > Post 94.10501 201.99112 > > Pre 101.63792 210.04248 > > Is that (something like) what you want? > > cheers, > > Rolf Turner > > P.S. You said: "I usually use GUI software". Now *there* lies your > problem. A GUI is a black box that removes all control over what is > going on, from your hands. > > R. T. > > > > > -- > Honorary Research Fellow > Department of Statistics > University of Auckland > Stats. Dep't. (secretaries) phone: > +64-9-373-7599 ext. 89622 > Home phone: +64-9-480-4619 > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] gsub issue with consecutive pattern finds
Hi Iris, Thank you. Further, very nice solution. Best, Iago On 01/03/2024 12:49, Iris Simmons wrote: > Hi Iago, > > > This is not a bug. It is expected. Patterns may not overlap. However, there > is a way to get the result you want using perl: > > ```R > gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) > ``` > > The specific change I made is called a positive lookahead, you can read > more about it here: > > https://www.regular-expressions.info/lookaround.html > > It's a way to check for a piece of text without consuming it in the match. > > Also, since you don't care about character case, it might be more legible > to add ignore.case = TRUE and remove the upper case characters: > > ```R > gsub("([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE, ignore.case = > TRUE) > > ## or > > gsub("(?i)([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE) > ``` > > I hope this helps! > > > On Fri, Mar 1, 2024, 06:37 Iago Giné Vázquez wrote: > >> Hi all, >> >> I tested next command: >> >> gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") >> >> with the following output: >> >> [1] "a_eri_ou_e" >> >> So, there are two consecutive vowels where an underscore is not added. >> >> May it be a bug? Is it expected (bug or not)? Is there any chance to get >> what I want (an underscore between each pair of consecutive vowels)? >> >> >> Thank you! >> >> Best regards, >> >> Iago >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] gsub issue with consecutive pattern finds
Hi Iago, This is not a bug. It is expected. Patterns may not overlap. However, there is a way to get the result you want using perl: ```R gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) ``` The specific change I made is called a positive lookahead, you can read more about it here: https://www.regular-expressions.info/lookaround.html It's a way to check for a piece of text without consuming it in the match. Also, since you don't care about character case, it might be more legible to add ignore.case = TRUE and remove the upper case characters: ```R gsub("([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE, ignore.case = TRUE) ## or gsub("(?i)([aeiou])(?=[aeiou])", "\\1_", "aerioue", perl = TRUE) ``` I hope this helps! On Fri, Mar 1, 2024, 06:37 Iago Giné Vázquez wrote: > Hi all, > > I tested next command: > > gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") > > with the following output: > > [1] "a_eri_ou_e" > > So, there are two consecutive vowels where an underscore is not added. > > May it be a bug? Is it expected (bug or not)? Is there any chance to get > what I want (an underscore between each pair of consecutive vowels)? > > > Thank you! > > Best regards, > > Iago > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] gsub issue with consecutive pattern finds
Hi all, I tested next command: gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") with the following output: [1] "a_eri_ou_e" So, there are two consecutive vowels where an underscore is not added. May it be a bug? Is it expected (bug or not)? Is there any chance to get what I want (an underscore between each pair of consecutive vowels)? Thank you! Best regards, Iago [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] converting MATLAB -> R | element-wise operation
> Berwin A Turlach > on Wed, 28 Feb 2024 17:42:27 +0800 writes: > On Tue, 27 Feb 2024 13:51:25 -0800 Jeff Newmiller via > R-help wrote: >> The fundamental data type in Matlab is a matrix... they >> don't have vectors, they have Nx1 matrices and 1xM >> matrices. > Also known as column vectors and row vectors. :) >> Vectors don't have any concept of "row" vs. "column". > They do in (numerical) linear algebra. And MATLAB was > written by numerical analysts for numerical analysts. :-) > So they distinguish between row and column vectors. > GAUSS also distinguishes between row and column vectors. There are *vectors* and they belong to a vector space and that's it. (and yes, arrays of a given rank and dimensions also are elements of a vector space, and hence matrices are, and then indeed, a 3x1 matrix and a 1x3 matrix are *not* members of the same vector space -- even though the two vector spaces are isomorphic to each other) The matlab induced --> applied linear algebra / math "column- and row-vectors" have been convenient because then everything is a matrix (or scalar), and that fits well with a product called "matlab" which is short for "matrix lab(oratory)". BUT they are mathematically confusing and therefore in my view very undesirable terminology. I'm very very strongly with Jeff that "the only" consistent language would be to call them 1-row matrix and 1-column matrix, because that's what they are, well defined and perfect within the well defined math realm of linear algebra. Yes, matrix-vector calculus , scalar products, bilinear forms, ... can be generalized in such ways that 1-row matrices and 1-column matrices can be treated equivalently to vectors and vice versa .. and that is sometimes convenient. Still, the "column-vector" and "row-vector" terms have lead to much confusion in my view, because really Nx1 or 1xM are dimensions of matrices and *not* of any vectors .. > R (and S) does not distinguish between row and column > vectors, and is in this aspect quite unique among the > groups of vector-oriented programming languages (AFAICT). I agree. And that's good -- because "vectors are vectors" aka "a rank-1 array is a rank-1 array is a rank-1 array" (Richard O'Keefe) > But treating every vector as a column vector, together > with the recycling rule, allows for the easy coding of the > matrix/vector calculations that one (mostly) comes across > in statistical computing. For the rare occasion when this > is not true the sweep() command is provided, typically > remembered once one was bitten by the lack of distinction > between row and column vectors. :) > Cheers, > Berwin Martin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.