Displaying 20 results from an estimated 6000 matches similar to: "return (x+1) * 1000"
2020 Nov 20
4
return (x+1) * 1000
I'm not thinking of complicated cases.
This happened to me in a function that returns 10 minute slots
slot <- function (seconds) {
return (seconds %/% 600) * 600
}
Obviously I found the issue while debugging and corrected my code with
surrounding parenthesis, but I was surprised that the R parser did not catch
this syntactic error.
This is especially poignant when we have to
2020 Nov 20
1
return (x+1) * 1000
I don't see how anything operating on the "result" of a return() call could be
legal. The special semantics of the return() call is that it does **not**
return control to the place it was called from, but rather to the location
where its surrounding function(){} was called from.
Mateo.
--
Mateo Obreg?n.
On Friday, 20 November 2020 22:52:58 GMT Duncan Murdoch wrote:
> On
2020 Nov 20
1
return (x+1) * 1000
FWIW, 'R CMD check --as-cran' in R-devel checks for "bogus return"
statements but I think that's only for the case when one forgets the
parentheses, e.g. 'return' instead of 'return()'.
I don't think it catches this case but I'm also not sure. Though, I can
imagine it might be possible to enhance the current check to include also
this case.
It could
2020 Nov 20
2
return (x+1) * 1000
And the related:
> f = function() stop(return("lol"))
> f()
[1] "lol"
I have a feeling all of this is just return() performing correctly though.
If there are already R CMD CHECK checks for this kind of thing (I
wasnt sure but I'm hearing from others there may be/are) that may be
(and/or may need to be) sufficient.
~G
On Fri, Nov 20, 2020 at 3:27 PM D?nes T?th
2020 Nov 20
2
return (x+1) * 1000
Without having dug into the details, it could be that one could update
the parser by making a 'return' a keyword and require it to be
followed by a parenthesis that optionally contains an expression
followed by end of statement (newline or semicolon). Such a
"promotion" of the 'return' statement seems backward compatible and
would end up throwing syntax errors on:
2020 Nov 21
1
return (x+1) * 1000
On 20/11/2020 7:01 p.m., Ben Bolker wrote:
> I may be unusual but I don't find these examples surprising at all/
> I don't think I would make these mistakes (maybe it's easier to make
> that mistake if you're used to a language where 'return' is a keyword
> rather than a function?
>
> My two cents would be that it would make more sense to (1) write
2020 Nov 20
0
return (x+1) * 1000
Perhaps the parser should warn if you use return() at all. It is rarely
needed and is akin to the evil 'GOTO' statement in that it makes the flow
of control less obvious to the reader.
-Bill
On Fri, Nov 20, 2020 at 2:37 PM Mateo Obreg?n <obregonmateo at gmail.com>
wrote:
> I'm not thinking of complicated cases.
>
> This happened to me in a function that returns 10
2020 Nov 20
0
return (x+1) * 1000
On 20/11/2020 5:36 p.m., Mateo Obreg?n wrote:
> I'm not thinking of complicated cases.
>
> This happened to me in a function that returns 10 minute slots
>
> slot <- function (seconds) {
> return (seconds %/% 600) * 600
> }
>
> Obviously I found the issue while debugging and corrected my code with
> surrounding parenthesis, but I was surprised that the
2020 Nov 20
0
return (x+1) * 1000
Hi all,
I can confirm this occurs for me as well.
The one thing that comes to mind is that there are certain larger
expressions that contain calls to return which we absolutely don't want to
be an error, e.g
if(somestuff)
return(TRUE)
That said, the actual expression Mateo pointed out certainly does look like
an error (it definitely isn't going to do what the developer intended).
2020 Nov 20
0
return (x+1) * 1000
Yes, the behaviour of return() is absolutely consistent. I am wondering
though how many experienced R developers would predict the correct
return value just by looking at those code snippets.
On 11/21/20 12:33 AM, Gabriel Becker wrote:
> And the related:
>
> > f = function() stop(return("lol"))
>
> > f()
>
> [1] "lol"
>
>
2020 Nov 21
0
return (x+1) * 1000
I may be unusual but I don't find these examples surprising at all/
I don't think I would make these mistakes (maybe it's easier to make
that mistake if you're used to a language where 'return' is a keyword
rather than a function?
My two cents would be that it would make more sense to (1) write
code to detect these constructions in existing R code (I'm not good at
2008 Oct 13
3
lattice panel question
Dear R users,
How to change lattice panel label/text from the automatically generated
label (based on the conditioning) to our own set of label?
for example:
someStuff <- data.frame(area = rep(c("SOUTH", "NORTH", "EAST", "WEST"), each
= 25),
group = rep(c("A","B","C","D"), each = 5),
2023 Aug 04
2
print only first level directory name when copying files
Hello,
I am copying /mnt/foo to /mnt/bar/
rsync --info=name1,del2 -rl /mnt/foo /mnt/bar/
/mnt/foo contains deep directory structure, ie:
/mnt/foo/aaa/
/mnt/foo/aaa/somestuff/
/mnt/foo/aaa/somestuff/file1
/mnt/foo/bbb/
/mnt/foo/bbb/someotherstuff/
/mnt/foo/bbb/someotherstuff/file2
I am not interested in details which individual files were copied, just
the main directory.
2023 Aug 04
1
print only first level directory name when copying files
Fourhundred Thecat via rsync <400thecat at lists.samba.org> wrote:
> I am copying /mnt/foo to /mnt/bar/
>
> rsync --info=name1,del2 -rl /mnt/foo /mnt/bar/
>
> /mnt/foo contains deep directory structure, ie:
>
> /mnt/foo/aaa/
> /mnt/foo/aaa/somestuff/
> /mnt/foo/aaa/somestuff/file1
>
> /mnt/foo/bbb/
> /mnt/foo/bbb/someotherstuff/
>
2006 Jul 21
10
why validation on server side
hi,
i have noticed that the validations in RoR happen at server side
mostly what sites do is using javascript they validate user information
there...
whats the point of doing it at the server side
is it that loading of javascript file in a browser makes a response to
client slow
and validation at server side offsets that....?????
any sugeestions????
is it that i am missing something as
2006 Feb 20
13
Agile Legacy Interop
I just wanted to announce my latest plugin: LegacyInterop
The 5 second video, minus the video, looks like this:
$ ./script/plugin install
svn://lirp.rubyforge.org/var/svn/lirp/trunk/legacy_interop
$ echo LegacyInterop.act_as_dotnet >> config/environment.rb
Done! Agile! Pragmatic!
The plugin includes support for a large number of legacy systems, all
using the "act_as" pattern.
2018 May 22
2
Using tryCatch in a for loop
Data and code as promised:
#Creating a test dataset
Year<- c(2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014)
Lake1<- c(2, 4, 5, 2, 1, 1, 2, 3, 4, 5, 6, 2, 3, 1, 2)
Lake2<- c(1, 3, -1, 4, -2, 1, 2, 3, 4, 5, 6, 2, 3, 1, 2)
Lake3<- c(1, 2, 5, -3, 1, 1, 2, 3, 4, 5, 6, 2, 3, 1, 2)
Lake4<- c(1, 1, 1, 1, 1, 1, 1, 250, 240, 240, 240, 240, 240, 239,
2018 May 22
0
Using tryCatch in a for loop
No. If your ouput is a numeric "matrix", it cannot include alpha. Columns
in a data frame can be of different classes, but each column must be single
class.
and finally, of course, see ?cat -- I think you are misusing it. If you
simply want to return "somestuff", your function should be:
function(w) {"somestuff"}
not
function(w) {cat("somestuff")}
As
2010 Jul 11
10
dependent support for has_many through?
Given the following
class Programmer < ActiveRecord::Base
has_many :assignments
has_many :projects, :through => :assignments
end
if I call Programmer#projects.clear, it will delete_all the joining
assignments; however, I have a situation where I''d like the
assignments to get destroyed instead so that their after_destroy
callbacks get called. It would be simple to
2010 Feb 24
5
XCP: Custom templates
Hello,
Is it possible to create a custom template for XCP? Or edit an existing
one? I know that I could create a VM and then exported as a template,
but I would prefer to create a template like "Debian Lenny 5.0" that
install debian from the network but with 64bits instead of the 32bits
used by the template.
--
Angel L. Mateo Martínez
Sección de Telemática
Área de Tecnologías de