[R] character set problem
Dear R-users, Last week I installed R 3.5.2 on a new MacBook Air. I got error messages for the wrong locale (character set). And simple math proved not to work: Upon typing this, I got: > 2ˆ2 Error: unexpected input in "2À" > The character visible as a caret is apparently coded as something very different. Then I changed things according to the FAQ, chapter 7, (switching all settings to English), and executed the recommended line: defaults write org.R-project.R force.LANG en_US.UTF-8 The error messages disappeared, but the problem remained. A fresh install of R 3.5.2 also didn't help: Here its startup messages, then a line testing the caret: > R version 3.5.2 (2018-12-20) -- "Eggshell Igloo" > Copyright (C) 2018 The R Foundation for Statistical Computing > Platform: x86_64-apple-darwin15.6.0 (64-bit) > > R is free software and comes with ABSOLUTELY NO WARRANTY. > You are welcome to redistribute it under certain conditions. > Type 'license()' or 'licence()' for distribution details. > > Natural language support but running in an English locale > > R is a collaborative project with many contributors. > Type 'contributors()' for more information and > 'citation()' on how to cite R or R packages in publications. > > Type 'demo()' for some demos, 'help()' for on-line help, or > 'help.start()' for an HTML browser interface to help. > Type 'q()' to quit R. > > [R.app GUI 1.70 (7612) x86_64-apple-darwin15.6.0] > > [History restored from /Users/fb/.Rapp.history] > >> 2ˆ2 > Error: unexpected input in "2À" >> Does anyone know how to get R (R.app) to interpret a caret as a caret? Thanks in advance, Franklin Bretschneider Utrecht University Utrecht, The Netherlands __ 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] [R-SIG-Mac] character set problem
Dear Kevin Ushey, Re: > On 19 Feb 2019, at 20:16, Kevin Ushey wrote: > > If I understand correctly, the problem is that the character your keyboard is > inserting is not a regular caret (^, \u0053); rather, it's a 'modifier > character circumflex accent' (ˆ, \u02c6). > > How are you inserting the carat on your laptop? For what it's worth, I get a > 'regular' caret with Shift + 6, and that particular accent character with Alt > + I. Thanks. Indeed I just type the normal shift-6, and get this strange circumflex character. With alt-i I get this same character. I can produce a normal caret by typing rawToChar(as.raw(94)) in the console, but that's of course rather clumsy. How to "tame" the editor to produce the normal ASCII caret? The other symbols in that row, like % and &, are the normal ASCII characters. Strange why this single character on my keyboard is a two-byte character. Any clue appreciated. Franklin Franklin Bretschneider Utrecht University Utrecht, The Netherlands __ 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] [R-SIG-Mac] character set problem
Dear Peter Anthoni, Re: > On 20 Feb 2019, at 07:22, Peter Anthoni wrote: > > is your keyboard type US. International -PC, that will insert the weird caret. > > > > cheers > > Peter That 's it!!! What I thought to be the most universal keyboard proved to be the culprit. Changed to simple "US" (SystemPreferences, Language and region, Keyboard preferences) and all is OK. Thanks a lot. With best regards, Franklin - - - - - Franklin Bretschneider Utrecht University Utrecht, The Netherlands __ 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] Image processing in R for BMI calculation
Hello Paul Bernal, (sorry, forgot to CC) Re: > Does anyone know about any package for image processing, for example, to > calculate body mass index pased on a picture, silouette or image. This sounds more like a job for the image analysis program NIH Image (the Java-version "ImageJ" being available for most platforms). ImageJ was designed for the analysis of microscopic images of cells etcetera, and can count, mark and measure objects. However, it works for 2D images unless jou have a stack of images. For R there is a Package ‘EBImage’ for image manipulation and measuring that might also be interesting (but also 2D I guess). Succes and Best regards, Franklin --- Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl f.bretschnei...@xs4all.nl Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl __ 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] Handling interrupts in long-running R functions
Dear Ivan Krylov, Re: > On 10 Sep 2021, at 16:43, Ivan Krylov wrote: > > Hello everyone, > > I'm writing an R function that may be running for "long" periods of > time (think tens of minutes), and I would like to be able to tell it: > "please stop what you're doing and return the not-yet converged results > as they are for inspection". > > The behaviour I'm striving for is > > 1) User presses interrupt > 2) Function handles the interrupt and returns as if the convergence > test passed > 3) By some black magic, the interrupt condition is raised on the > previous function call level (to avoid the situation where my > function is called in a loop by some other function and the user > wants to interrupt the whole process, not just my function). > > Is this a good idea? Is (3) even possible? (I guess I could check the > length of sys.parents() and avoid recovering from the interrupt if > called from some other function, but that feels dirty.) Could something > similar be achieved with options(error = recover) and R restarts? Are > there other ways of, well, interrupting the execution of R functions > without changing the semantics of interrupts in R? > > I've been working with MATLAB lately (when in Rome, do as Romans > do...), and their idiom for my desired behaviour is "create a plot > window and return when that window is closed", but that doesn't > translate well to R. > > -- > Best regards, > Ivan Just a crazy idea: the sound input of a Mac/PC might serve as an interrupt. Record a short bit and assess the amplitude: moderate = signal, loud = break. See my source code below. This works on my MacBook Air with Mojave. When I snap my fingers, the amplitude is moderate (3 through 10), when tapping or scratching the microphone, amplitude is over 20. Hoping this might help, With best regards, Franklin -- R source code: # sound as interrupt.R # with package audio # 15-09-2021 # # NB First switch audio input to the wanted device # (microphone, sound input or 3rd party device) # flick your fingers = signal (m about 3 through 10) # tap the microphone -> stop (m > 20) library(audio) samp.rate = 44100 rectime = 1 # second nsamples = samp.rate * rectime repeat { sample <- record(2*nsamples, rate=44100, channels=2) wait(sample) # wait for the recording to finish sound <- sample$data # get the result m = max(sound) print(m) if (m > 0.5) alarm() # or the desired routine if (m > 20) {save.wave(sound, "sound from audio input.wav"); break} # stop program } # end Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl __ 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] Playing a music file in R
Hello vahid.borji, Re: > How can we call a music file from our laptop (for example from desktop) and > play it in R? Could you please give me an explicit example by writing > commands in R. Is it necessary for our music file to be in a specific > format? If yes, which format it has to be? Wave files, and probably a few other formata, can be loaded, saved and manupulated with (a.o.) these packages: library(signal) library(seewave) library(tuneR) In addition, to play a wave file, a small Unix file is necessary, called "play". It must be attached by the following line: setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc. Then, a simple script like the following will do: inname = file.choose() ywave=readWave(inname) ster=ywave@stereo srate=yw...@samp.rate play(ywave) Hoping this helps, I remain With best regards, Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl __ 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] Playing a music file in R
Dear Vahid, Re: > I have a question regarding the following code: > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ># path depends on your R version etc. > > How can I find the corresponding path on my laptop? This line ... setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ... is the path on my MacBook Air running Mac OS Mojave. The structure of R on similar computers and OS versions will be the same, but I don't know if you use Windows or Linux. Maybe an R-user working with Windows or Linux can help. Success, Franklin Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl __ 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] Playing a music file in R
Dear Vahid, Re: > I have a question regarding the following code: > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ># path depends on your R version etc. > > How can I find the corresponding path on my laptop? This line ... setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ... is the path on my MacBook Air running Mac OS Mojave. The structure of R on similar computers and OS versions will be the same, but I don't know if you use Windows or Linux. Maybe an R-user working with Windows or Linux can help. Success, Franklin Franklin Bretschneider Dept of Biology Utrecht University f.bretschnei...@uu.nl __ 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.